everything seems okay , where is the problem ? can you explain ? problem link : http://mirror.codeforces.com/contest/855/problem/B
my code : https://paste.ubuntu.com/25608466/
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
everything seems okay , where is the problem ? can you explain ? problem link : http://mirror.codeforces.com/contest/855/problem/B
my code : https://paste.ubuntu.com/25608466/
Название |
---|
consider this input: 3 1 1 -1 -1 100 1000
should output: 1000
your solution: -1
But why ? i was always taking the maximum answer greedily....!!!
1 ≤ i ≤ j ≤ k ≤ n.
ooo , may be got it , thank you.
As I told you before, greedy approach will not work here.
You can try Dynamic programming to solve this type of problem where greedy doesn't work. But for this there is a brute force solution.
for each number in the array, let's say that this is aj and we multiply it with q. So we are fixing the middle element every time. Now we have to find ai and ak [i ≤ j and j ≤ k] such that ai * p + ak * r is maximized. So we can easily get an O(n2) solution. How to make it O(n)? Well the array is static. So we can pre-calculate the minimum and maximum in each suffix and prefix of the array and use them instead of running a loop each time to find ai and ak. This is the same solution described in the editorial btw.