Thirsty Ants
Time limit1sMemory limit128 MB
Ants on a line walk at unit speed toward the nearest fallen dew drop, and the task asks for every ant's position when the last drop is drunk.
- Level
Hard9 of 10
- Topics
- Simulation, Sorting, Heap, Intervals
- Solved
- No attempts yet
Problem
There are thirsty ants placed on a number line. Initially the -th ant is at the point with coordinate , and .
Drops of dew fall onto the line. The -th drop falls at time onto the point with coordinate , where . If at some moment there is no drop on the line, every ant stays still. Otherwise each ant moves at unit speed toward the drop nearest to it; if the two nearest drops are equally far (one to the left and one to the right), the ant moves toward the left one. As soon as an ant reaches a drop, it drinks that drop.
Drinking a drop may change how the ants move afterward. If several ants reach one drop at the same instant, they share its water equally and drink it immediately. In particular, more than one ant may occupy the same point. If a drop falls exactly onto an ant, it is drunk at the very instant it lands and does not influence the ants' movement in any way.
Determine the position of every ant at the moment the last drop of dew is drunk, that is, when no drop remains on the line.
Input
The first line contains the number of ants (). The second line contains a non-decreasing sequence of integers (), the positions of the ants. The third line contains the number of events (). Each of the next lines contains two integers and (), meaning that at time a drop of dew fell onto the point with coordinate . The events are given in non-decreasing order of .
Output
Print integers on a single line, separated by single spaces, giving the position of each ant at the moment the last drop is consumed. Print them in non-decreasing order.