| II SBC São Paulo Programming Marathon |
|---|
| Закончено |
Marquinhos Carlsen is a great enthusiast of the game of chess. Although chess is played on an $$$8 \times 8$$$ board, Marquinhos enjoys performing mathematical analyses by imagining an infinite chessboard placed on a Cartesian plane. His favorite chess piece is the knight (knight in English), because it has a very interesting movement pattern. On an infinite board, a knight always has $$$8$$$ possible "L"-shaped moves: on each move, the knight must move $$$2$$$ squares in one direction and $$$1$$$ square in a perpendicular direction.
In the figure below, a knight at position $$$(2,2)$$$ can move to positions $$$(1,4)$$$, $$$(3,4)$$$, $$$(0,3)$$$, $$$(4,3)$$$, $$$(0,1)$$$, $$$(4,1)$$$, $$$(1,0)$$$, and $$$(3,0)$$$. Squares are represented by their lower-left corner coordinates in the Cartesian plane.
In one of his mathematical analyses, Marquinhos placed $$$N$$$ knights on this infinite board and defined the "knight distance" of every board position as the minimum number of moves required for at least one of the knights to reach that position.
Using this, he also defined the "knight number" of every position, which is a unique positive integer assigned according to the following ordering of all positions on the board: first, positions are ordered by increasing knight distance; ties are broken by decreasing vertical coordinate; and any remaining ties are broken by increasing horizontal coordinate.
In the figure below, two knights are placed at positions $$$(2,2)$$$ and $$$(5,3)$$$. Each visible position is labeled with its "knight number". Note that there are infinitely many positions outside the figure that are not shown, including positions with negative coordinates.
Marquinhos wants your help analyzing the "knight number". He has a list of $$$Q$$$ positive integers and wants to know, for each of them, which position on the infinite chessboard has the corresponding knight number.
The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 10$$$), indicating the number of knights.
The next $$$N$$$ lines each contain two integers $$$X_i$$$ and $$$Y_i$$$ ($$$0 \leq X_i, Y_i \leq 10^9$$$), indicating the positions of the $$$N$$$ knights on the board. Positions are represented by their lower-left corner coordinates, as in the figures, and all knights occupy distinct positions.
The next line contains an integer $$$Q$$$ ($$$1 \leq Q \leq 10$$$).
The following line contains $$$Q$$$ integers $$$K_i$$$ ($$$1 \leq K_i \leq 10^9$$$), indicating the "knight numbers" whose corresponding board positions must be determined.
Your program must print $$$Q$$$ lines. The $$$i$$$-th line should contain two integers $$$A_i$$$ and $$$B_i$$$ such that the "knight number" of position $$$(A_i, B_i)$$$ is equal to $$$K_i$$$.
11 191 2 3 4 5 6 7 8 9
1 1 0 3 2 3 -1 2 3 2 -1 0 3 0 0 -1 2 -1
22 25 37213 190 7 25 1000 10000 100000
0 0 7 5 7 4 -1 5 -1 18 -51 14 121 138
| Название |
|---|


