8689: The Great Wall II

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述


Beacon towers are built throughout and alongside the Great Wall. There was once a time when there were nnn beacon towers built from west to east for defending against the invaders. The altitude of the iii-th beacon tower, based on historical records, is aia_iai.

The defenders divide strategically all beacon towers into kkk parts where each part contains several, but at least one, consecutive beacon towers. To fully defend against the invaders, to each part a team of defenders should be assigned, the cost of which is given by the highest altitudes of beacon towers in that part.

As a historian, you are dying to know the minimum costs of assignments for every k=1,2,…,nk = 1, 2, \ldots, nk=1,2,,n.


输入格式


The first line contains an integer nnn (1≤n≤8000)(1 \leq n \leq 8\,000)(1n8000), denoting the number of beacon towers alongside the Great Wall.
The second line contains nnn integers a1,a2,…,ana_1, a_2, \ldots, a_na1,a2,,an, where the iii-th integer aia_iai (1≤ai≤100000)(1 \leq a_i \leq 100\,000)(1ai100000) is the altitude of the iii-th beacon tower.

输出格式


Output nnn lines, the iii-th of which contains an integer indicating the minimum cost for k=ik = ik=i.

输入样例 复制

5
1 2 3 4 5

输出样例 复制

5
6
8
11
15

分类标签