Coding Spree

It's almost report card time, so of course everyone has started programming like mad. There are only T (1 ≤ T ≤ 1000) hours left before the Sunday midnight deadline!

Luckily, you've earned your points gradually, so now you can just sit back and watch your classmates struggle. One of your friends in particular is really screwed, so he's decided to skip school all week and go on a coding spree.

Though your friend is lazy, he has done some problems on the Judge, so now he has exactly N (1 ≤ N ≤ 1000) problems available to him. No more problems will be posted until after the deadline, and he can't get partial marks on any of these problems. Problem i is worth Vi points and he knows in advance that he can solve it in Hi hours (1 ≤ Vi, Hi ≤ 1000).

You're not a very pleasant person, so you want to torture your friend a bit. You plan to calculate the most points your friend could possibly get by the deadline, just so you can taunt him with that number.

Input

Line 1: The integers N and T
The next N lines: Line i+1 contains the integers Vi and Hi

Output

Output the maximum amount of points your friend can get in at most T hours of coding.

Sample Input

8 48
10 7
5 1
50 30
5 1
10 5
100 1000
25 10
60 40

Sample Output

95

Explanation

Your friend only has 48 hours, and 8 problems to choose from. To maximize his points, he should do problems 2, 3, 4, 5, and 7, giving him 95 points in 47 hours.

All Submissions
Best Solutions


Point Value: 10 (partial)
Time Limit: 1.00s
Memory Limit: 16M
Added: Jan 05, 2009
Author: SourSpinach

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)


seems to be working fine with me think.gif

I got AC on this problem with a solution a few months ago that terminates if there is insufficient input, and I just confirmed that nothing looks fishy about the input data.

I guess the problem is related to cin as it disappeared when I switched to scan().

so it's impossible to beat Hanson on this one I guess.

LOL C FTW

or i mean, resubmit FTW xD

You're going to get banned if you keep doing this.


This is a basic example of a "Knapsack Problem".
Think of breaking this down into the subproblem "what's the maximum number of points I can get in X hours, using some set of the first Y problems".