#P9515. Maximize Check‐Ins on a Timeline
Maximize Check‐Ins on a Timeline
Maximize Check‐Ins on a Timeline
You are standing at the origin on a straight road, which can be regarded as the number line. There are n check‐in stops. The i-th stop is located at position \(x_i\) and it will start operating at time \(a_i\) (i.e. from time \(a_i\) onward, you are allowed to check in at that stop). Checking in takes no time at all.
You start at time 0 from position 0. At each time unit you may move at most 1 unit (in either direction). You must reach the destination point \(f\) at or before time \(t\), and from time \(t\) onward you must remain at \(f\). You can check in at a stop only if you arrive at it no earlier than its opening time. Note that you are free to visit the stops in any order.
Determine the maximum number of stops at which you can check in while still being able to reach \(f\) by time \(t\).
Note: All formulas are rendered in LaTeX format.
inputFormat
The first line contains three integers \(n\), \(t\), and \(f\) — the number of stops, the deadline time, and the destination coordinate respectively.
Each of the following \(n\) lines contains two integers \(x_i\) and \(a_i\), representing the coordinate of the \(i\)-th stop and the time at which it starts operating.
It is guaranteed that \(f \le t\) and all values are integers.
outputFormat
Output a single integer: the maximum number of stops at which you can check in while reaching \(f\) by time \(t\).
sample
3 10 5
1 1
2 2
3 3
3