#BS0000150. Những sinh vật chất nhầy (Slimes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những sinh vật chất nhầy (Slimes)
Slimes
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are slimes in a line, numbered from to . Slime initially has size .
During each second, if possible, exactly one slime eats an adjacent slime. A slime may eat its neighbor only when it is strictly larger. The eater gains the eaten slime's size, the eaten slime disappears, and adjacency is updated in the remaining line. The process stops when no move is possible.
For each original slime, find the smallest number of seconds until it can be eaten in some valid sequence of moves. Each slime can be considered under a different sequence of moves. Print if it cannot be eaten.
Input
- The first line contains , the number of initial slimes.
- The second line contains the sizes from left to right.
Output
Print integers: the minimum seconds before each original slime is eaten, or when impossible.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
5
2 2 3 1 4
Output
2 1 2 1 3
Explanation
For the initial line :
- Slime can be eaten in seconds: slime eats slime , then slime .
- Slime can be eaten by slime in second.
- Slime can be eaten in seconds: slime eats slime and grows to size , then eats slime .
- Slime can be eaten by slime immediately.
- Slime can be eaten in seconds: slime first eats slime (growing to ), next slime (growing to ), then slime . These choices illustrate why different targets may use different move sequences. The output is
2 1 2 1 3.