#P9848. Cloud Retainer’s Pinball Challenge
Cloud Retainer’s Pinball Challenge
Cloud Retainer’s Pinball Challenge
Cloud Retainer, the builder of the Dwelling in the clouds above Qingyun Peak, has designed a pinball game for the upcoming Lantern Rite Festival in Liyue. The game is played on the 2D plane between two horizontal lines at y = 0 and y = H. There are n wooden boards and m coins on the field, each represented by a point. The i-th wooden board is at \( (x_i, y_i) \) and the i-th coin is at \( (x'_i, y'_i) \).
The pinball is released from \( (10^{-9}, 10^{-9}) \) with an initial velocity \( \vec{v}=(1,1) \). After being released, if the ball is at \( (x,y) \) then after \( \epsilon \) seconds it will be at \( (x+\epsilon, y+\epsilon) \), unless its velocity is changed by a bounce.
Whenever the ball hits one of the horizontal boundaries (y=0 or y=H) or a wooden board, its vertical velocity is reversed (i.e. \( v_y \) becomes \( -v_y \)) while the horizontal velocity remains unchanged. If the ball passes through a coin, the player’s score increases by 1 (and the coin is considered collected) without changing the velocity.
Before the ball is released the player may remove any number of wooden boards (even none), so that only the remaining boards will cause a bounce when hit. Note that the ball will always bounce at the boundaries regardless of any removals.
The motion of the ball is completely determined by the sequence of bounces. In any segment between two consecutive bounces the ball moves in a straight line with slope either +1 or -1. More precisely, if a bounce happens at \( (x_0,y_0) \) with current direction \( d \) (where \( d=+1 \) means upward and \( d=-1 \) means downward), then until the next bounce the ball follows the line
- If \( d = +1 \): \( y = y_0 + (x-x_0) \). (This segment lasts until \( x=x_0+H-y_0 \), when the ball would hit \( y=H \).
- If \( d = -1 \): \( y = y_0 - (x-x_0) \). (This segment lasts until \( x=x_0+y_0 \), when the ball would hit \( y=0 \).
The player may choose to force an earlier bounce if there is a wooden board exactly on the current trajectory. For an upward segment (with \( d=+1 \)), a board at \( (x,y) \) is hit if and only if
[ y - x = y_0 - x_0, \quad x_0 < x \leq x_0 + (H-y_0). ]
Similarly, for a downward segment (with \( d=-1 \)), a board at \( (x,y) \) is hit if and only if
[ y + x = y_0 + x_0, \quad x_0 < x \leq x_0+y_0. ]
The ball collects all coins that lie exactly on its path. That is, a coin at \( (a,b) \) is collected in a segment starting at \( (x_0,y_0) \) with direction \( d \) if
- For \( d=+1 \): \( b = y_0 + (a-x_0) \) and \( x_0 < a \leq x_0+ (H-y_0) \).
- For \( d=-1 \): \( b = y_0 - (a-x_0) \) and \( x_0 < a \leq x_0+y_0 \).
Assuming the ball moves for an astronomically long time (\(10^{10^{10^{10^{10}}}}\) seconds), compute the maximum score (number of coins collected) the player can achieve by optimally choosing which wooden boards to remove.
Input Format
The first line contains three integers: H n m
(H
is the height of the plane, n
is the number of wooden boards, and m
is the number of coins).
The next n
lines each contain two integers xi yi
, representing the coordinates of the wooden boards.
The following m
lines each contain two integers x'_i y'_i
, representing the coordinates of the coins.
Output Format
Output a single integer, the maximum score achievable.
inputFormat
The input begins with a line containing three integers H n m
.
Then follow n
lines, each with two integers xi yi
— the positions of the wooden boards.
Then follow m
lines, each with two integers x'_i y'_i
— the positions of the coins.
All coordinates are integers.
outputFormat
Output a single integer — the maximum number of coins that can be collected.
sample
5 2 4
4 3
10 5
3 3
6 4
8 2
11 1
4