Unable to solve the problem Editorial is also not available . Can anybody explain? Thanks in advance:)
# | User | Rating |
---|---|---|
1 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 166 |
3 | Um_nik | 161 |
3 | atcoder_official | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
Unable to solve the problem Editorial is also not available . Can anybody explain? Thanks in advance:)
Name |
---|
Store an array b where b[i] is the sum of all aj = i
So in the sample, b would be {2, 10, 6}, the problem turns into a simple DP problem, if you are at state i you have 2 options:
1) leave b[i] and move to state i + 1
2) take b[i] and move to state i + R + 1
Giving WA:(
It will be wrong for test case 1 2 1 2 1 3
Sorry missed one more thing, you should set R = min(L, R)
because if you start taking elements in increasing order, then the difference between every consecutive values should be at least R
and if you start taking elements in decreasing order, then the difference between every two consecutive values should be at least L
The optimal solution is to choose the order which gives the minimum difference between consecutive values which is min(L, R)
code
Thanks:) Got it.
hey mate can u explain why it should be min(l,r) and not max(l,r)?? update :-> i got it,still thanks!!
It can be done with this way as well: do DP twice..from index 0 and going to right with distance R and from index 1e5 with distance L, then pick the maximum of the two values obtained.