To support students preparing for the upcoming City Level Talent Exam, the teacher has prepared ~n~ exercises ~( 1 \leq n \leq 10^5 )~. The exercises are numbered from ~1~ to ~n~. Each exercise is aimed at developing certain skills, such as programming techniques, algorithms, data structures, etc.
For efficient self-practice, each exercise has a minimum skill requirement. To solve the ~i~-th exercise, the student needs a minimum skill level of ~a_i~. This means that a student can solve the ~i~-th exercise if and only if their skill level is at least ~a_i~. If the ~i~-th exercise is solved, the student's skill level will increase by ~b_i~ (~ 1 \leq a_i, b_i \leq 10^9 ~). Initially, the student's skill level before solving any exercises is ~c~ (~ 0 \leq c \leq 10^9 ~). The exercises can be done in any order.
For example: with an initial skill level of ~c = 1 ~, ~n = 4 ~, and the corresponding values of ~a_i, b_i ~ being ~ (1, 10), (21, 5), (1, 10), (100, 100) ~, the student would solve exercise ~1~, then exercise ~3~, and finally exercise ~2~. Thus, they can solve a total of ~3~ exercises.
Requirement: Given the integers ~n~, ~c~ and the pairs ~(a_i, b_i)~ for ~ 1 \leq i \leq n ~, determine the maximum number of exercises that can be solved.
Input
- The first line contains two integers ~ n ~ and ~ c ~.
- The next ~ n ~ lines each contain two integers ~ a_i ~ and ~ b_i ~. The numbers in the same line are separated by one space.
Output
- Output a single integer that indicates the maximum number of exercises that can be solved.
Sample Input
4 1
1 10
21 5
1 10
100 100
Sample Output
3
Bình luận