Robots
Time limit1sMemory limit1024 MB
Robots on a circular track move clockwise for given durations, pushing each other and stopping at walls; find each final position.
- Level
Hard8 of 10
- Topics
- Simulation, Intervals, Sorting, Two pointers
- Solved
- No attempts yet
Problem
Robotics builder Daumilas has constructed robots and wants to test them in a circular arena. The arena is divided into sections, numbered to clockwise: for section borders section , and section additionally borders section .
Each section may be left empty, or hold a single robot or a single wall (never both). Daumilas gives robot a command . Then every robot starts moving at the same instant. Robot travels clockwise at a constant speed of one section per second for seconds. If stationary robots lie in its path, it pushes them forward without slowing down. A robot stops before its command is finished (before all seconds pass) only when it, or a robot it is pushing, comes up against a wall. Only one robot fits in a section, and robots can never pass through one another.
Determine which section each robot occupies once the simulation ends.
Input
The first line contains three integers , , and — the number of sections, the number of robots, and the number of walls.
Each of the next lines contains two integers and — the starting section of robot and its command.
The last line contains integers — the section of each wall (this line is empty when ).
Robots and walls are each listed in increasing order of section, and all listed sections are distinct.
Output
Output integers separated by single spaces on one line. The -th integer is the section occupied by the -th robot (in the input order) when the simulation ends.
Constraints
- Robots are given in increasing order of their starting section.
- Walls are given in increasing order of their section.
- No section holds more than one object (a wall or a robot).