#P2107. Lab Room Marathon
Lab Room Marathon
Lab Room Marathon
In Little Z's hometown, there is a street lined with computer labs. In each lab, thousands of students are busy solving problems. After finishing a session on CodeChef, Little Z decides to take a walk. On Lab Street there are \( n \) labs. The \( i\)th lab is located at coordinate \( x_i \) (with \( x_i \ge 0 \)) and the time required to think and solve problems at that lab is \( t_i \). Little Z lives at the coordinate \( 0 \) and moves at a speed of \( 1 \) (so the time taken to travel from a point \( a \) to a point \( b \) is \( |a-b| \)).
When Little Z reaches a lab, he can choose either to stop and spend \( t_i \) time to think (and then he instantly aces the lab) or simply pass by. He has at most \( m \) units of time before he must head to his next contest.
If he decides to visit a sequence of labs, assume that he visits them in order of increasing coordinates. Note that if the farthest (rightmost) visited lab has coordinate \( X \), then the overall travel time (starting from 0) is \( X \), regardless of how many labs he visits along the way. In other words, if he visits a subset of labs with indices \( i_1, i_2, \dots, i_k \) (with \( x_{i_1} \le x_{i_2} \le \cdots \le x_{i_k} \)), the total time spent is \[ T = x_{i_k} + \sum_{j=1}^{k} t_{i_j} \le m. \]
Your task is to determine the maximum number of labs at which Little Z can stop and solve problems within the time limit \( m \).
Input format: The first line of input contains two integers \( n \) and \( m \). Each of the following \( n \) lines contains two integers \( x_i \) and \( t_i \), representing the coordinate of the lab and the thinking time at that lab respectively. It is guaranteed that \( x_i \ge 0 \) for all \( i \), but the labs are not necessarily given in sorted order.
Output format: Output a single integer, the maximum number of labs at which Little Z can solve problems.
Note: Little Z may skip some labs if needed. When visiting labs, he always travels along the street from his home (coordinate 0) towards the right. The travel time is determined solely by the farthest lab he visits.
inputFormat
Input is given as follows:
n m x1 t1 x2 t2 ... xn tn
Here, \( n \) is the number of labs, \( m \) is the total available time, and for each lab, \( x_i \) (\( 0 \le x_i \le 10^9 \)) denotes its coordinate and \( t_i \) (\( 0 \le t_i \le 10^9 \)) is the thinking time needed.
outputFormat
Output a single integer representing the maximum number of labs Little Z can visit (i.e. solve the problems) within the time limit.
sample
3 10
1 2
3 5
6 1
2