Under construction

Still being built. Things may change

Departure

Time limit4sMemory limit512 MB

Summary
Given bus routes whose speed depends on distance, find for each home the earliest arrival time from the stadium at 0, as an exact fraction of days.
Level

Hard9 of 10

Topics
Shortest path, Sorting, Math
Solved
No attempts yet

Problem

The final match of the prestigious national football championship has just ended. It is midnight, and football fans from across the country have gathered at the national stadium, the largest sports venue in Mouseland, and are leaving to head home by bus.

Mouseland is modelled as a very long straight east-west road, and its inhabitants live in houses along it. The national stadium is the most important building in Mouseland, so it sits at kilometre zero. Every location is given as a single number relative to the stadium. Locations east of the stadium are positive, and locations west are negative. For example, 10 is ten kilometres east of the stadium, and -4 is four kilometres west. The stadium is at location 0.

There are N public bus routes along this road. Each route runs one bus each day. The i-th bus travels from S_i to E_i at a constant speed and direction, leaving at midnight and reaching its destination at midnight the next day. Every midnight, an identical bus leaves each route's start location for the same destination. The speed of a bus depends on the distance it has to cover. Routes are one-directional, so there may be no bus running the opposite way.

People can board a bus, alight from it, and transfer between buses at the same location instantly, at any point along a route, even while the bus is moving.

M people left the national stadium at midnight. The j-th person lives at P_j. For each person, find the minimum time needed to get home by bus.

Input

The first line contains N and M, the number of bus routes and the number of people. Each of the next N lines contains S_i and E_i, the start and destination locations of the i-th bus route. The last line contains M integers, where the j-th integer is the location of the j-th person's home.

Output

Print exactly M lines. On line j, print two integers A_j and B_j such that Aj/BjA_j / B_j is in lowest terms (gcd(A_j, B_j) = 1) and equals the minimum number of days the j-th person needs to get home by bus. Report the exact value, including any fractional part. For example, if the earliest arrival is noon on the fourth day, then 3.5 days have passed, so the answer is 7/27/2, printed as '7 2'. It is guaranteed that every person can eventually get home by bus.

Constraints

  • 1≤N≤1061 \le N \le 10^6
  • 1≤M≤1061 \le M \le 10^6
  • −106≤Si,Ei≤106-10^6 \le S_i, E_i \le 10^6 for all 1≤i≤N1 \le i \le N
  • −106≤Pj≤106-10^6 \le P_j \le 10^6 for all 1≤j≤M1 \le j \le M
  • Si≠EiS_i \ne E_i for all 1≤i≤N1 \le i \le N
  • Pj≠0P_j \ne 0 for all 1≤j≤M1 \le j \le M

For any integer xx, sign(x)\text{sign}(x) is 1 if xx is positive, 0 if xx is zero, and -1 if xx is negative.

Examples3

  1. Example 1

    Input
    5 8
    0 5
    3 11
    1 -8
    4 10
    1 -3
    1 2 5 6 8 -3 -7 11
    
    Expected output
    1 5
    2 5
    1 1
    4 3
    13 8
    4 9
    8 9
    2 1
    
  2. Example 2

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

    Input
    5 3
    0 2
    2 4
    4 6
    6 8
    8 10
    9 10 10
    
    Expected output
    9 2
    5 1
    5 1