#P10772. [NOISG 2021 Qualification] Departure
[NOISG 2021 Qualification] Departure
Problem Description
There is a city with routes. On each route, every day at midnight, a bus departs from the starting point and arrives at the destination at midnight of the next day. The start of the -th bus is , and the end is . People can board, get off, or transfer at any position along a bus route.
The stadium is the center of this city, with coordinate . A point kilometers to the west of the stadium has coordinate , and a point kilometers to the east has coordinate .
Now there are people who need to go home from the stadium. You need to find the shortest time for each person to get home.
Input Format
The first line contains two integers .
Lines to each contain two integers .
Line contains integers , representing each person's home.
Output Format
Output lines. Each line contains two integers (), meaning that this person can get home at the earliest after days.
5 8
0 5
3 11
1 -8
4 10
1 -3
1 2 5 6 8 -3 -7 11
1 5
2 5
1 1
4 3
13 8
4 9
8 9
2 1
3 2
-1 4
-2 5
0 -5
4 -4
6 7
4 5
5 3
0 2
2 4
4 6
6 8
8 10
9 10 10
9 2
5 1
5 1
Hint
Constraints
This problem uses bundled testdata.
Define $\operatorname{sign}(x) = \begin{cases} 1 &\text{if } x > 0 \\ 0 &\text{if } x = 0 \\ -1 &\text{if } x < 0 \\ \end{cases}$.
Subtask 0 is the sample.
Subtask 1 (10 pts): , , $\operatorname{sign}(S_i)\neq\operatorname{sign}(E_i)$.
Subtask 2 (14 pts): , .
Subtask 3 (12 pts): , , it is guaranteed that the final answer values are all no more than , and any coordinate lies on no more than routes.
Subtask 4 (8 pts): , it is guaranteed that any coordinate lies on no more than routes.
Subtask 5 (15 pts): , it is guaranteed that the final answer values are all no more than .
Subtask 6 (13 pts): $\operatorname{sign}(S_i)\neq\operatorname{sign}(E_i)$.
Subtask 7 (28 pts): no special constraints.
It is guaranteed that , , , and .
Translated by ChatGPT 5