Problem P
Procrastination
Kelly has procrastinated all of his work and left it until the final week of the semester. He doesn’t have time to finish everything, but he wants to feel good about his productivity. He has decided to prioritize completing as many assignments as possible, even if his grade suffers. Thus, Kelly wants to maximize the number of assignments he completes in the time he has left (not his grade!). If there are multiple assignments that would take the same amount of time, but he cannot do all of them in the time he has remaining, he will opt to complete the assignment which will increase his grade the most first.
Input
The first line of input contains two integers $N$ and $M$ ($1 \leq N \leq 10^5, 1 \leq M \leq 10^9$) — The number of tasks Kelly has to complete and the number of hours he has to complete them, respectively.
The next $N$ lines describe Kelly’s tasks. Each line contains two space-separated integers $T$ and $G$ ($1 \leq T,G \leq 10^9$) — The time required (in hours) to complete this task, and amount by which it will increase his grade.
Output
Print out a single integer representing the grade Kelly will receive after completing as many tasks as he can in the time remaining.
Sample Input 1 | Sample Output 1 |
---|---|
3 10 1 10 9 80 5 20 |
30 |
Sample Input 2 | Sample Output 2 |
---|---|
5 14 4 10 6 25 6 20 2 15 1 5 |
55 |
Sample Input 3 | Sample Output 3 |
---|---|
2 10 5 10 5 12 |
22 |
Sample Input 4 | Sample Output 4 |
---|---|
2 9 5 10 5 12 |
12 |