#P8484. 「HGOI-1」Mole

    ID: 9359 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP贪心线段树洛谷原创O2优化洛谷月赛

「HGOI-1」Mole

Background

brealid\text{brealid} thinks that the normal whack-a-mole game is too simple\text{simple}. So she designed a brand-new whack-a-mole game.

Problem Description

On a game window of length ll, there is a mole sequence of length tt (lt)(l \le t). 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 ll 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 (tl+1)(t-l+1) seconds.

Each mole in sequence TT has its own height hih_i. Each time, the player may choose to hit one mole. The player gains a coin reward equal to the mole’s height value hih_i, and at the same time the height hih_i of mole ii decreases by one.

After research, brealid\text{brealid} 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 brealid\text{brealid} tells you the window length ll, the sequence length tt, and the mole height sequence TT generated in a certain game. Our lovely brealid\text{brealid} 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 1,2,(tl+1)1,2,\cdots (t-l+1), respectively.

Input Format

The first line contains two integers ll and tt, representing the window length ll and the sequence length tt.

The second line contains tt integers, representing the mole height sequence in a certain round.

Output Format

Output one line with tl+1t-l+1 integers a1,a2,atl+1a_1,a_2,\cdots a_{t-l+1}, where aia_i denotes the maximum number of coins that can be obtained if the game ends at second ii.

5 10
1 3 1 1 1 1 1 1 5 1
3 5 6 7 12 16

Hint

Sample Explanation

Second 1: hit 22, add 33 to the answer.

Second 2: hit 22, add 22 to the answer.

Second 3: hit any one, add 11 to the answer.

Second 4: hit any one again (a non-00 one), add 11 to the answer.

Second 5: hit 99, add 55 to the answer.

Second 6: hit 99, add 44 to the answer.

Constraints

This problem uses bundled testdata. There are 44 subtask\text{subtask} in total, and the final score is the sum of the scores of all subtask\text{subtask}.

$$\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 100%100\% of the testdata, 1lt1061\le l\le t\le 10^6, hi109|h_i|\le 10^9.

Translated by ChatGPT 5