Endless Road
Time limit5sMemory limit1024 MB
Given N segments on a line of length 10^9, output the order in which members plant, always choosing the one with the least newly covered length (ties by index).
- Level
Hard8 of 10
- Topics
- Segment tree, Greedy, Intervals
- Solved
- No attempts yet
Statement
Whenever KAIST students leave campus, they usually walk along a straight road called the Endless Road. Many students feel the road never ends, partly because the scenery along it is dull. We model the Endless Road as a straight line of length . A position on the line is a real number .
The members of RUN@KAIST decided to plant flowers of different colors along the road to liven it up. There are members, numbered from to . At the last regular meeting, each member was assigned a nonempty segment on the line, which contains every position with .
A member with a higher index carries more responsibility in the club, so the segment length does not decrease as the index grows: for all .
Flower planting takes place in turns. In each turn, one member who has not been selected yet plants flowers. The selected member plants flowers over their segment , except at positions where other members have already planted flowers.
The next member is chosen as follows. The member who would plant the fewest flowers at that moment goes first. The amount planted is the length of the part of the segment where the member plants new flowers, and this length may be zero. If several members tie, the member with the smallest index goes first.
Jaeung must announce the planting schedule. Find the order in which all members plant flowers under these rules.
Input
The first line contains an integer . Each of the next lines contains two integers and .
Output
Print space-separated integers. The -th integer is the index of the member who plants flowers in the -th turn.
Constraints
. . for all . All intervals are distinct, that is, for all .