题目描述
Problem Description
Takahashi is choosing snacks to bring on a school trip. He can bring snacks worth a total of up to $ P $ yen. However, since his homeroom teacher, Sensei, is kind, he will allow Takahashi to bring snacks that exceed the limit as long as removing any single snack would bring the total within the limit.
For example, if he can bring snacks worth up to 100 yen, bringing snacks worth 30 yen, 40 yen, and 50 yen each would be allowed because removing any single snack would keep the total under 100 yen. However, bringing snacks worth 40 yen, 50 yen, and 60 yen each would not be allowed because even if the 40 yen snack is removed, the total would still be 110 yen, exceeding the limit.
Takahashi has $ N $ types of snacks he wants to bring, each with a price and a satisfaction level. For each type of snack, he can bring at most one. Determine the maximum total satisfaction he can achieve with the snacks that Sensei will allow.
Input Format
The input is given from the standard input in the following format:
$ N $ $ P $ $ a_1 $ $ b_1 $ $ a_2 $ $ b_2 $ : $ a_N $ $ b_N $
- The first line contains two integers $N,\ P\ (1\ ≦\ N\ ≦\ 5,000,\ 1\ ≦\ P\ ≦\ 5,000)$ representing the number of types of snacks Takahashi wants to bring and the total amount of money he can spend on snacks, separated by spaces.
- The next $ N $ lines contain two integers each, $a_i\ b_i\ (1\ ≦\ a_i\ ≦\ 100,\ 1\ ≦\ b_i\ ≦\ 100)$, representing the price and satisfaction level of each snack, separated by spaces.
Output Format
Output the maximum total satisfaction Takahashi can achieve with the snacks that Sensei will allow, on a single line.
Sample Input and Output
Sample Input #1
4 100
30 50
40 40
50 100
60 80
Sample Output #1
190
Sample Input #2
5 100
40 10
30 50
60 80
20 40
20 70
Sample Output #2
200
Sample Input #3
10 654
76 54
62 19
8 5
29 75
28 4
76 16
96 24
79 30
20 64
23 56
Sample Output #3
347
Notes/Hints
Partial Points
This problem has partial points.
- If you solve the problem for the dataset where $1\ ≦\ N\ ≦\ 100,\ 1\ ≦\ P\ ≦\ 100$, you will be awarded 50 points.
Sample Explanation 1
Choosing the first, second, and third snacks gives a total satisfaction of 190, which is the maximum among the choices that Sensei will allow.
Sample Explanation 3
This input is not included in the partial points dataset.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分