408612: GYM103202 L Forged in the Barrens

Memory Limit:1024 MB Time Limit:6 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Forged in the Barrenstime limit per test6 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Beacon towers are built throughout the Barrens. There was once a time when there were $$$n$$$ beacon towers built from west to east for defending against the invaders. The altitude of the $$$i$$$-th beacon tower, based on historical records, is $$$a_i$$$.

The defenders divide strategically all beacon towers into $$$k$$$ parts where each part contains several, but at least one, consecutive beacon towers. The scale of an individual part is given by the difference between the highest and the lowest altitudes of beacon towers, and the most sensible partition maximizes the sum of scales of all parts.

As a historian, you are dying to know the maximum sums of scales for every $$$k = 1, 2, \ldots, n$$$.

Input

The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 2 \times 10^5)$$$, denoting the number of beacon towers throughout the Barrens.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq 10^9)$$$ is the altitudes of the beacon towers in order.

Output

Output $$$n$$$ lines, the $$$i$$$th of which contains an integer indicating the maximum sum for $$$k = i$$$.

ExamplesInput
5
1 2 3 4 5
Output
4
3
2
1
0
Input
5
1 2 1 2 1
Output
1
2
2
1
0

加入题单

算法标签: