Procrastination

시간 제한2초메모리 제한2048 MB

요약
M시간 안에 최대 개수의 과제를 끝내되 시간이 같은 과제가 있으면 성적이 가장 많이 오르는 것을 먼저 골라, 얻는 총 성적을 출력한다.
난이도

보통10점 중 4점

유형
그리디, 정렬
정답자
아직 제출이 없습니다

문제

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.

입력

The first line of input contains two integers NN and MM (1≤N≤105,1≤M≤1091 \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 NN lines describe Kelly's tasks. Each line contains two space-separated integers TT and GG (1≤T,G≤1091 \leq T,G \leq 10^9) --- The time required (in hours) to complete this task, and amount by which it will increase his grade.

출력

Print out a single integer representing the grade Kelly will receive after completing as many tasks as he can in the time remaining.

예제4

  1. 예제 1

    입력
    3 10
    1 10
    9 80
    5 20
    
    예상 출력
    30
    
  2. 예제 2

    입력
    5 14
    4 10 
    6 25
    6 20
    2 15
    1 5
    
    예상 출력
    55
    
  3. 예제 3

    입력
    2 10
    5 10
    5 12
    
    예상 출력
    22
    
  4. 예제 4

    입력
    2 9
    5 10
    5 12
    
    예상 출력
    12