1. 程式人生 > >POJ3624手鍊

POJ3624手鍊

POJ3624 Description


Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).


Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.


Input


* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di


Output


* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints


Sample Input


4 6
1 4
2 6
3 12
2 7
Sample Output


23


Description
貝茜在珠寶店閒逛時,買到了一箇中意的手鐲。很自然地,
她想從她收集的 N(1 <= N <= 3402)塊寶石中選出最好的那些鑲在手鐲上。
對於第i塊寶石,它的重量為W_i(1 <= W_i <= 400),
並且貝茜知道它在鑲上手鐲後能為自己增加的魅力值D_i(1 <= D_i <= 100)。
由於貝茜只能忍受重量不超過M(1 <= M <= 12880)的手鐲,她可能無法把所有喜歡的寶石都鑲上。
於是貝茜找到了你,告訴了你她所有寶石的屬性以及她能忍受的重量,希望你能幫她計算一下,
按照最合理的方案鑲嵌寶石的話,她的魅力值最多能增加多少。


輸入
* 第1行: 2個用空格隔開的整數:N 和 M
* 第2..N+1行: 第i+1行為2個用空格隔開的整數:W_i、D_i,分別為第i塊寶石 的重量與能為貝茜增加的魅力值


輸出

* 1行:一個整數,是魅力的有利條件,可以實現給定的重量限制的最大數