Rightplant
Time limit1sMemory limit1024 MB
Given N, build an arrangement of heights 1 to N so that the total number of direction reversals over all rightward branch fires is maximized.
- Level
Hard8 of 10
- Topics
- Array, Simulation, Greedy
- Solved
- No attempts yet
Problem
There are buildings in a row, each with a distinct integer height from to . The height of the -th building from the left is .
If a branch is fired to the right from a building of height , the branch flies over buildings whose height is at most . When the branch hits a building taller than , that building's height decreases by , and the branch reverses direction.
A branch fired right from a building of height flies over a building shorter than
A branch fired right from a building of height flies over a building of height
A branch fired right from a building of height hits a building taller than and reverses direction
Fire a branch to the right from the -th building from the left. Let be the number of times that branch changes direction until it flies past the leftmost or rightmost building. Find the sequence that maximizes .
Input
The first line contains an integer . ()
Output
Print the elements of a sequence that maximizes , separated by spaces. If there are several such sequences, print any of them.