#P6564. [POI 2007] 堆积木KLO
[POI 2007] 堆积木KLO
Problem Description
PinkRabbit got a tall tower made of stacked blocks from his npy, and each block has a number written on it. Let the number on the -th block from bottom to top be . We directly denote a tower whose numbers are by . PinkRabbit defines the value of a tower as .
PinkRabbit can delete any number of blocks from the current tower. The remaining blocks will fall under gravity until they cannot fall anymore. For example, if we delete the second block from bottom to top in the tower , we get the tower , and the value of the new tower is .
PinkRabbit wants to delete any number of blocks from the current tower so that the value of the final tower is maximized. Since he always wins, he asks you to answer this question.
Input Format
The first line contains a positive integer , indicating the initial height of the tower.
The second line contains positive integers , where is the number on the -th block from bottom to top in the initial state.
Output Format
Output one integer in one line, indicating the maximum value that can be obtained.
5
1 1 2 5 4
3
Hint
Explanation of Sample 1
In the initial state , only satisfies , so the total value is .
Delete the second block from bottom to top, and we get . Then all satisfy , so the total value is .
It is easy to prove that there is no better plan.
Constraints
For of the testdata, , 。
Translated by ChatGPT 5