#P2694. Coin Catching Challenge
Coin Catching Challenge
Coin Catching Challenge
In a 2D coordinate system, there are \(n\) coins labeled from \(0\) to \(n-1\). Initially, the \(i\)-th coin is at the position \((x_i, y_i)\). Every second, each coin moves 1 unit downwards, i.e. a coin located at \((x,y)\) at some time will be at \((x, y-t)\) after \(t\) seconds. Initially, FJ is at \((0,0)\) and he can move horizontally by at most 1 unit per second (or choose not to move). If at any moment a coin’s position coincides with FJ’s position, FJ catches that coin. Determine whether FJ can catch all coins. If he can, output Abletocatch
; otherwise, output Notabletocatch
.
Notes:
- The catch time for a coin initially at \((x_i, y_i)\) is exactly \(y_i\), since the coin falls 1 unit per second.
- FJ must be at \(x_i\) at time \(y_i\) to catch the coin.
- Since coins fall at a constant rate, the order in which coins must be caught is fixed by increasing \(y_i\) (i.e. the coin with the smaller \(y_i\) comes first).
- If two coins have the same \(y_i\) but different \(x_i\), it is impossible to catch both.
The problem can be solved by simulating FJ's horizontal movement. Start at \(t=0\) and position \(0\). Sort the coins by \(y_i\). For each coin, check if FJ can move from his last position to the coin's \(x_i\) in the available time (which is the difference in the coin's catch time and the current time). If \(|x_i - \text{current_position}|\) exceeds the available time, output Notabletocatch
; otherwise, update FJ's position and time to that coin's position and catch time. If FJ can catch all coins, output Abletocatch
.
inputFormat
The first line contains an integer \(n\) \( (1 \le n \le 10^5)\), representing the number of coins. Each of the following \(n\) lines contains two integers \(x_i\) and \(y_i\) \(( -10^9 \le x_i \le 10^9,\ 0 \le y_i \le 10^9 )\), denoting the initial coordinates of the \(i\)-th coin.
outputFormat
Output a single line: Abletocatch
if FJ can catch all coins, or Notabletocatch
otherwise.
sample
3
0 2
1 4
2 6
Abletocatch