How to Fail at Programming Contest
Time limit1sMemory limit512 MB
Gennady picks the order of problems he solves, never starting one he cannot finish, to minimize total points scored within T minutes.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Sorting, Greedy
- Solved
- No attempts yet
Problem
Gennady is the best at competitive programming. He can solve any problem, so he has never lost a contest. But today he has decided to lose a contest, because winning every contest is not interesting.
Gennady cannot simply abandon solving problems, since that is unsportsmanlike behavior. So he has decided to pick a bad strategy that minimizes his total points for the contest.
There are problems in the contest, numbered from to . If a contestant solves problem , he gets points. Gennady has read all the problems and came up with a solution for each one. He knows that for problem he needs exactly minutes to write the solution. The final thing to do is to choose the order in which he writes the solutions. Gennady noticed that he has minutes remaining until the end of the contest.
Gennady wants to use the following strategy. He chooses a problem he has not solved yet and writes a solution for it. He never chooses a problem he cannot finish in time. When the solution is ready, Gennady submits it and gets points for this problem. Submitting and testing take no time. Then he moves on to another problem. When Gennady realizes he cannot solve any of the remaining problems in time, he stops coding.
Now Gennady wants to choose the order of solving problems that minimizes his score for the contest. Help him find the smallest number of points he can get while following the rules above.
Input
The first line of input contains two integers and , the number of problems and the time until the end of the contest ().
The following lines describe the problems. The -th line contains two integers , , the time Gennady needs to solve this problem and the number of points this problem is worth (, ).
Output
Output one number: the minimal number of points Gennady can get.