Impressive Beers

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

요약
서로 다른 맥주들의 부분집합을 골라 예산 안에서 가격 합이 M 이하가 되도록 하면서 행복 합을 최대로 만든다.
난이도

보통10점 중 4점

유형
동적 계획법, 배열
정답자
아직 제출이 없습니다

문제

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≤N≤500N, 1 \le N \le 500 the number of different beers the pub offers, and M,1≤M≤10000M, 1 \le M \le 10000 the amount of money that you have.

Followed by NN lines with on each line a type of beer which is indicated by two integers: p,1≤p≤1000p, 1 \le p \le 1000, the price of the beer and h,1≤h≤1000h, 1 \le h \le 1000, the happiness you will gain from this beer.

출력

A single line with a single integer HH, the maximal happiness you can gain by buying different kinds of beers, within your budget.

예제2

  1. 예제 1

    입력
    5 20
    20 50
    10 30
    5 15
    4 12
    9 20
    
    예상 출력
    57
    
  2. 예제 2

    입력
    5 100
    20 50
    10 30
    5 15
    4 12
    9 20
    
    예상 출력
    127