Comments

https://codeforces.me/contest/2014/submission/282533590 Does anyone have an idea why this gets WA on test 3? Apparently it outputs "yes" instead of a "no" but with the program being so simple I can't find what the problem may be, I solved it with an XOR segment tree, even though there probably are more simple and efficient approaches.

Edit: Discovered the case: 1 4 1 4 5 6 7 1 4

Where it should output "no" but it outputs "yes" and fixed the problem with random hashing because the values are only between 1 and 1e6

It should work in the worst case for the starting element that you have chosen, that's why the problem comes down to finding the starting element for which the worst case is the least of all the other worst cases.

The answer is 8 because you can choose to start at the monster 6 and for every option you take at whatever point in time you can always kill all the monsters.

Those are not the only cases. For example, in an array with 5 elements (1-indexed), if you start at index 3, you can also go 3->4->2->5->1. At any moment in time, if there are 2 indexes that you've not visited adjacent to indexes that you have visited, you can go in either one of the 2, that's why it's important to account for all possible ways. But yes, in the solution, you're basically assuming the worst case scenario, that is, if the index is to the left of the starting element you're assuming it first went to the right and only then came left so that by the time it reaches that index, the power will be the minimum. The same goes for when the index is to the right of the starting index, only in reverse.

If you start at index 4 with power 7 you than kill the index 5 with power 6 and the index 6 with power 5, now you don't have enough power left to kill the monster at index 4. Remember, since the monster killed is chosen randomly between the 2 options possible (or 1 if there are no 2 possible options), you have to account for the worst case scenario. Sure, power 7 would've worked if you killed index 3 first, then the indexes >4 and than the indexes <3, but that's only one case, we have to account for all possible cases.

Check out this test:

8
1 11 1 1 12 1 1 1

Here, if we choose the monster with 12 health we need x = 17, but if we choose to start from the monster with health 11 we only need x = 16.

We can't choose the monster with 12 and have x = 16 because we kill that monster and all monster to the right and our power decreases to 12, we kill the monster to the left of it with 12 and we get to 11, we kill the left monster again and we are down to 10, this is less than what we need to kill the monster with 11 health.

Thank you!

Same

Same but I'm at least happy that others have also considered this contest harder than usual for a Div 3, I could not solve the 3rd problem and I got stuck there. I tried D to maybe at least solve 3 problems but I couldn't. Well better luck next time, I need to work more