This page is still under construction.

Parts of this page are still being built. What you see may change.

Robots

Time limit1sMemory limit1024 MB

Summary
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 MM robots and wants to test them in a circular arena. The arena is divided into NN sections, numbered 11 to NN clockwise: for 1≤i≤N−11 \le i \le N-1 section ii borders section i+1i+1, and section NN additionally borders section 11.

Each section may be left empty, or hold a single robot or a single wall (never both). Daumilas gives robot ii a command aia_i. Then every robot starts moving at the same instant. Robot ii travels clockwise at a constant speed of one section per second for aia_i 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 aia_i 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 NN, MM, and KK — the number of sections, the number of robots, and the number of walls.

Each of the next MM lines contains two integers xix_i and aia_i — the starting section of robot ii and its command.

The last line contains KK integers yiy_i — the section of each wall (this line is empty when K=0K = 0).

Robots and walls are each listed in increasing order of section, and all listed sections are distinct.

Output

Output MM integers separated by single spaces on one line. The ii-th integer is the section occupied by the ii-th robot (in the input order) when the simulation ends.

Constraints

  • 3≤N≤1093 \le N \le 10^9
  • 1≤M≤2⋅1051 \le M \le 2 \cdot 10^5
  • 0≤K≤2⋅1050 \le K \le 2 \cdot 10^5
  • M+K≤NM + K \le N
  • 0≤ai≤N−10 \le a_i \le N - 1
  • 1≤xi,yi≤N1 \le x_i, y_i \le N
  • 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).

Examples4

  1. Example 1

    Input
    8 4 1
    3 2
    5 3
    6 0
    8 0
    2
    
    Expected output
    5 7 8 1
    
  2. Example 2

    Input
    10 1 0
    5 3
    
    Expected output
    8
    
  3. Example 3

    Input
    12 2 0
    2 5
    4 0
    
    Expected output
    7 8
    
  4. Example 4

    Input
    10 2 0
    9 4
    10 0
    
    Expected output
    3 4