#P3407. 散步
散步
Description
On a road, positions are represented by integers .
When , there is a royal palace. If , it means meters to the east of the palace; if , it means meters to the west of the palace.
Along the road, there are houses labeled from west to east. Each house has exactly one person. Houses exist only at even integer points.
The king believes that the citizens’ fitness is declining and orders everyone to go out for a stroll. Every citizen can walk meter per second. Each citizen walks either east or west; these directions are known to you. All citizens start their stroll simultaneously when the order is issued.
However, the citizens are very talkative. If two people meet during the stroll, they stop and talk. If a walking person reaches a point that coincides with someone who has already stopped, they will also stop and talk. Once they stop, they will chat endlessly and forget about the stroll.
Now seconds have passed since the order was issued. There are important persons of interest, and the king wants to know their positions. Can you help him?
Input Format
The first line contains integers .
The next lines each contain two integers . is the home coordinate. If is , the person walks east; if it is , the person walks west. It is guaranteed that the are in strictly increasing order and no two people share the same initial position.
The next lines each contain one integer: the index of a person of interest (indexed to from west to east).
Output Format
Output lines. Each line contains one integer, the coordinate of that person.
6 6 4
-10 1
-6 2
-4 1
2 1
6 2
18 2
2
3
4
6
-8
2
4
12
Hint
of the testdata: , .
Another of the testdata: .
Another of the testdata: starting from the westernmost, some consecutive citizens all walk east, and the remaining citizens all walk west.
of the testdata: are even, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号