#P6304. [eJOI 2018] 山

[eJOI 2018] 山

Description

There are nn mountains in the city of Innopolis. The height of the ii-th mountain is aia_i.

For beauty, you can build a house on a mountain only if it is strictly higher than the mountains on both sides of it (if they exist).

There is an excavator. Each hour, it can decrease the height of any one mountain by 11. At the same time, the excavator can work on only one mountain. A mountain’s height can be reduced to 00 or negative.

For each 1kn21\leq k\leq \lceil\frac{n}{2}\rceil, find the minimum number of hours the excavator needs to work in order to build kk houses (that is, to make at least kk mountains satisfy the condition above).

Input Format

The first line contains one integer nn.

The second line contains nn integers a1na_{1\cdots n}, representing the sequence {ai}\{a_i\}.

Output Format

Output one line with n2\lceil\frac{n}{2}\rceil integers. The ii-th integer is the answer when k=ik=i.

5
1 1 1 1 1
1 2 2
3
1 2 3
0 2
5
1 2 3 2 2
0 1 3

Hint

[Explanation for Sample 1]

Decrease the height of mountain 22 by 11. The heights become 1,0,1,1,11,0,1,1,1. Now mountain 11 satisfies the condition.

Then decrease the height of mountain 44 by 11. The heights become 1,0,1,0,11,0,1,0,1. Now mountains 1,3,51,3,5 satisfy the condition.


[Constraints]

For 100%100\% of the testdata, 1n5×1031\leq n\leq 5\times 10^3, 1ai1051\leq a_i\leq 10^5.

Subtask ID Score Constraints
11 00 Sample
22 77 n=3,ai100n=3,a_i\leq 100
33 1515 n10,ai100n\leq 10,a_i\leq 100
44 1313 n100,ai100n\leq 100,a_i\leq 100
55 1818 n100,ai2×103n\leq 100,a_i\leq 2\times 10^3
66 2222 n500n\leq 500
77 2525 No special constraints

Source: eJOI2018 Problem A “Hills”.

Note: The translation is from LOJ.

Translated by ChatGPT 5