№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Название |
---|
Kadane's Algorithm is not what this problem asks you about.
Your task is to maximize reminder modulo M, not sum itself.
If M=7 then 6 is better than 14, because 6 gives 6 modulo 7, and 14 gives 0 modulo 7 (and 6 is, obviously, more than 0).
Your solution will fail on following test
Here is my solution from a contest.
Well, I know what does the problem ask me about, but I think that we can modify Kadane's Algorithm to solve this problem. Sum solutions can be converted to Mod solutions.
I read the editorial of this problem and I almost got the idea but I prefer to edit my ideas. Please notify me if you can solve this problem by modifying Kadane's.
Here is my idea for this solution. Firstly as mentioned by I_love_Tanya_Romanova this problem is not what you have thought earlier. so , suppose you are maintaining curr_sum % m then you have to maximise the sum of the array ending at each index i then take maximum of all. let us consider curr_sum[i] denotes the sum of all elements from 1 to i % m now to maximise this there are two cases only decrease the smallest value less than curr_sum[i] from curr_sum which is obviously 0 else you can subtract the value just greater than curr_sum[i] (consider this value as x). we can see curr_sum[i] — x is negative so we have to add m to it which implies we have to maximise this (curr_sum[i] — x + m) or (m+curr_sump[i] — x) so take the smallest value greater than curr_sum[i] which can be easily find by maintaining a set (denoting by S in my code). hope this is useful in some way or other.