| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 (추가 시간 없음) | 2048 MB | 36 | 26 | 24 | 70.588% |
You and your friends find yourselves in a bar after class. As you are a really big fan of specialty beers you want to drink as many different beers as possible. Only issue of course being that you are still a student, and therefore you do not have enough money to buy every beer in the pub.
But of course, all beers are not created equally! You know of every type of beer the price and how much happiness it will give you. As you want to be as happy as possible, and being a Delft student, you want to find out how much happiness you can buy using an optimal strategy. So you decide to write a program that tells you how much happiness you can buy with a given amount of money. But since you like to drink different beers, you will never order the same beer twice, your program should take this into account.
One line with two integers: $N, 1 \le N \le 500$ the number of different beers the pub offers, and $M, 1 \le M \le 10000$ the amount of money that you have.
Followed by $N$ lines with on each line a type of beer which is indicated by two integers: $p, 1 \le p \le 1000,ドル the price of the beer and $h, 1 \le h \le 1000,ドル the happiness you will gain from this beer.
A single line with a single integer $H,ドル the maximal happiness you can gain by buying different kinds of beers, within your budget.
5 20 20 50 10 30 5 15 4 12 9 20
57
In the first sample your max happiness will be 57, as you can buy the beers priced 10, 5 and 4 to come to a hapiness of 57 (with a singe coin left to spend, buy there is no more beer you could buy for this price). Every other combination will give you less hapiness or will cost more than your budget. (for example, the beers of 10 + 9 will give you only 50 hapiness).
5 100 20 50 10 30 5 15 4 12 9 20
127
In the second sample you will buy each beer, giving you 127 hapiness, but it will not give you any more satisfaction to buy the same beer multiple times, so you are stuck at 127 and have some money left.