시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB3051285430.857%

문제

Oliver is a manager of a bank near KTH and wants to close soon. There are many people standing in the queue wanting to put cash into their accounts after they heard that the bank increased the interest rates by 42% (from 0.01% per year to 0.0142% per year).

However, there are too many people and only one counter is open which can serve one person per minute. Greedy as Oliver is, he would like to select some people in the queue, so that the total amount of cash stored by these people is as big as possible and that money then can work for the bank overnight.

There is a problem, though. Some people don’t have the time to wait until the bank closes because they have to run somewhere else, so they have to be served before a certain time, after which they just leave. Oliver also turned off the infrared door sensor outside the bank, so that no more people can enter, because it’s already too crowded in the hall.

Help Oliver calculate how much cash he can get from the people currently standing in the queue before the bank closes by serving at most one person per minute.

입력

The first line of input contains two integers N (1 ≤ N ≤ 10 000) and T (1 ≤ T ≤ 47), the number of people in the queue and the time in minutes until Oliver closes the bank. Then follow N lines, each with 2 integers ci and ti, denoting the amount of cash in Swedish crowns person i has and the time in minutes from now after which person i leaves if not served. Note that it takes one minute to serve a person and you must begin serving a person at time ti at the latest. You can assume that 1 ≤ ci ≤ 100 000 and 0 ≤ ti < T.

출력

Output one line with the maximum amount of money you can get from the people in the queue before the bank closes.

예제 입력 1

4 4
1000 1
2000 2
500 2
1200 0

예제 출력 1

4200

예제 입력 2

3 4
1000 0
2000 1
500 1

예제 출력 2

3000

출처

Contest > KTH Challenge > KTH Challenge 2013 F번

  • 문제를 만든 사람: Lukáš Poláček