题目收集
题目列表题单
返回列表

Monster Train 2

CodeforcesP0074· 2000ms· 1024 MB· ZJU Summer 2026 Contest 7原题链接
模拟数据结构优化

创建于 2026/07/18 · 更新于 2026/07/18

题目描述

Monster Train 2 is an excellent roguelike deck-building game. During combat, friendly units attack enemy units every turn. Consider a friendly unit that has all three effects Quick, Trample, and Sweep: it attacks before enemy units, hits every enemy unit, and carries excess damage onward.

There are nnn enemy units on the same floor, arranged from front to back and numbered 1,2,…,n1, 2, \ldots, n1,2,…,n in that order. The iii-th enemy unit has aia_iai​ Health, where aia_iai​ is a positive integer.

For this problem, the unit's Attack is a non-negative integer BBB. At the beginning of its turn, the combined effect of Quick, Trample, and Sweep is modeled as follows:

  1. First, all enemy units simultaneously take BBB damage.
  2. Every enemy unit whose remaining Health is non-positive dies in the first step. If its remaining Health is negative, it produces B−aiB-a_iB−ai​ excess damage; if its remaining Health is exactly 000, it produces no excess damage.
  3. Each enemy unit that died in the first step sends its excess damage to the nearest enemy unit behind it that survived the first step. If there is no surviving enemy unit behind it, the damage wraps around to the frontmost surviving enemy unit.
  4. All excess damage is applied simultaneously and is carried over only once. An enemy unit killed by excess damage does not pass on any further damage.

If no enemy unit survives the first step, all of them are immediately considered defeated.

For every m=1,2,…,nm=1, 2, \ldots, nm=1,2,…,n, suppose that only the first mmm enemy units are present. Find the minimum Attack BBB required for the friendly unit to defeat all of them in this turn.

输入格式

The first line contains one integer nnn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^51≤n≤5⋅105), the number of enemy units.

The second line contains nnn integers a1,a2,…,ana_1, a_2, \ldots, a_na1​,a2​,…,an​ (1≤ai≤1091 \le a_i \le 10^91≤ai​≤109), the initial Health values of the enemy units in front-to-back order.

输出格式

Output nnn integers. The mmm-th integer must be the answer when only the first mmm enemy units are present.

样例输入 #1

5
1 4 2 5 3

样例输出 #1

1 3 3 4 4