#P8484. 「HGOI-1」Mole
「HGOI-1」Mole
Background
thinks that the normal whack-a-mole game is too . So she designed a brand-new whack-a-mole game.
Problem Description
On a game window of length , there is a mole sequence of length . Initially, the left end of the sequence is aligned with the left end of the window. Then the sequence moves one unit per second (that is, the leftmost mole leaves the window, and the rightmost mole enters the window), scrolling left until the player ends the game or the right end of the sequence coincides with the right end of the window (so the window always contains moles at any time).
In the first second after the game starts, the sequence does not move. It is not hard to see that the game will last at most seconds.
Each mole in sequence has its own height . Each time, the player may choose to hit one mole. The player gains a coin reward equal to the mole’s height value , and at the same time the height of mole decreases by one.
After research, adjusted the game speed so that while the mole sequence moves by one unit, the player can hit at most once (or choose not to hit).
Now tells you the window length , the sequence length , and the mole height sequence generated in a certain game. Our lovely wants to know the maximum coins she can get if she ends the game at any moment, that is, the maximum coins obtainable when stopping at second , respectively.
Input Format
The first line contains two integers and , representing the window length and the sequence length .
The second line contains integers, representing the mole height sequence in a certain round.
Output Format
Output one line with integers , where denotes the maximum number of coins that can be obtained if the game ends at second .
5 10
1 3 1 1 1 1 1 1 5 1
3 5 6 7 12 16
Hint
Sample Explanation
Second 1: hit , add to the answer.
Second 2: hit , add to the answer.
Second 3: hit any one, add to the answer.
Second 4: hit any one again (a non- one), add to the answer.
Second 5: hit , add to the answer.
Second 6: hit , add to the answer.
Constraints
This problem uses bundled testdata. There are in total, and the final score is the sum of the scores of all .
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|}\hline \textbf{Task} & \textbf{Score} & l\le t\le \cr\hline 1 & 10 & 10 \cr\hline 2 & 20 & 500 \cr\hline 3 & 30 & 5000 \cr\hline 4 & 40 & 10^6 \cr\hline \end{array}$$For of the testdata, , .
Translated by ChatGPT 5