Hi everyone. Can somebody please help me to solve this problem. Thank you very much. It is from JBOI 2015, it's called Startup.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Название |
---|
I think it can be solved with some clever "bruteforce" approach. The first observation you should make is that for the given sequence a1, a2, ..., an we should consider sequences in form ak, ak + 1, ..., an, a1, a2, ..., ak - 1. So we should take some suffix of a and put it in front of it. Another small idea: instead of checking every prefix sum we can just check one, the minimal. So we have a correct presented sequence b1, b2, ... , bn if and only if . After we conclude this we can come up with an O(N) algorithm that solves the problem by calculating the above value for prefixes and suffixes.
I hope it helps if you have more questions just ask.
Thank you veru much, i will try to solve the problem after this algorithm, later and i will tell you if it worked.
Hi thanks for answering my question but i am still not able to solve it, may be you could be more specific or show me the code, but of course it would be better to explain more than to show me the code. Thank you very much.
Here is the code for the solution, it got 100 points thanks to mraron. Here is the code. Explenation: What it does is basically calculate two arrays of length n, L and R. L[i] means the smallest prefix sum of the original array till index i (you can see the recurrence in the code). R[i] means the smallest prefix sum of suffix i..n-1 (as you can see it in the code)
From then we shall see that the ith rotation meets the conditions if and only if R[i]>=0 (because i..n-1 suffix will be the new start of the array) and sum of the elements from i to n-1 plus L[i-1] is non negative because otherwise we would have some negative prefix in the middle. If you draw it, it becomes more clearer.