100 atcoder#ABC128F. [ABC128F] Frog Jump
[ABC128F] Frog Jump
Score : points
Problem Statement
There is an infinitely large pond, which we consider as a number line. In this pond, there are lotuses floating at coordinates , , , ..., and . On the lotus at coordinate , an integer is written.
You are standing on the lotus at coordinate . You will play a game that proceeds as follows:
- . Choose positive integers and . Your score is initially .
- . Let be your current coordinate, and . The lotus at coordinate disappears, and you move to coordinate .- If , the game ends.
- If and there is a lotus floating at coordinate , your score increases by .
- If and there is no lotus floating at coordinate , you drown. Your score decreases by points, and the game ends.
- . Let be your current coordinate, and . The lotus at coordinate disappears, and you move to coordinate .- If , the game ends.
- If and there is a lotus floating at coordinate , your score increases by .
- If and there is no lotus floating at coordinate , you drown. Your score decreases by points, and the game ends.
- . Go back to step .
You want to end the game with as high a score as possible. What is the score obtained by the optimal choice of and ?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the score obtained by the optimal choice of and .
5
0 2 5 1 0
3
If you choose and , the game proceeds as follows:
- Move to coordinate . Your score increases by .
- Move to coordinate . Your score increases by .
- Move to coordinate . The game ends with a score of .
There is no way to end the game with a score of or higher, so the answer is . Note that you cannot land the lotus at coordinate without drowning later.
6
0 10 -7 -4 -13 0
0
The optimal strategy here is to land the final lotus immediately by choosing (the value of does not matter).
11
0 -4 0 -99 31 14 -15 -39 43 18 0
59