AtCoder Regular Contest 189 (Div. 2)
D
Takahashi is Slime
AtCoder
⌀ 2006
原题
← CE →
翻译中…

Problem Statement

翻译中…

There are $N$ slimes lined up in a row from left to right. For $i = 1, 2, \ldots, N$, the $i$-th slime from the left has size $A_i$. For each $K = 1, 2, \ldots, N$, solve the following problem.

翻译中…

Takahashi is the $K$-th slime from the left in the initial state. Find the maximum size that he can have after performing the following action any number of times, possibly zero:

  • Choose a slime adjacent to him that is strictly smaller than him, and absorb it. As a result, the absorbed slime disappears, and Takahashi's size increases by the size of the absorbed slime.

When a slime disappears due to absorption, the gap is immediately closed, and the slimes that were adjacent to the disappearing slime (if they exist) become adjacent (see the explanation in Sample Input 1).

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 5 \times 10^5$
  • $1 \leq A_i \leq 10^9$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \ldots A_N

翻译中…

Output

翻译中…

Print the answers $B_K$ for each $K = 1, 2, \ldots, N$, separated by spaces, in the following format:

翻译中…

B_1 B_2 \ldots B_N

翻译中…

样例

Input #1
6
4 13 2 3 2 6
Output #1
4 30 2 13 2 13
As an example, consider the problem for $K = 4$. We will refer to the sizes of the remaining slimes, listed from left to right, with Takahashi's size enclosed in square brackets $[ ]$, as the **state of the row**. That is, the initial state is $(4, 13, 2, [3], 2, 6)$. Consider the following sequence of actions by Takahashi. - He absorbs the slime to his right. As a result, the absorbed slime disappears, and his size becomes $3 + 2 = 5$. The state becomes $(4, 13, 2, [5], 6)$. - He absorbs the slime to his left. As a result, the absorbed slime disappears, and his size becomes $5 + 2 = 7$. The state becomes $(4, 13, [7], 6)$. - He absorbs the slime to his right. As a result, the absorbed slime disappears, and his size becomes $7 + 6 = 13$. The state becomes $(4, 13, [13])$. There are no slimes adjacent to him that are strictly smaller than him, so he cannot perform any more actions. His final size is $13$, which is the maximum possible.
Input #2
12
22 25 61 10 21 37 2 14 5 8 6 24
Output #2
22 47 235 10 31 235 2 235 5 235 6 235
题目信息
题号
arc189_d
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。