|
|||
Ecstasy of GoldDirty Fred and his ferocious gang successfully broke into the treasury of Goliath Multicontinental Bank at last! Inside the treasury they found a deposit of gold bars. The bars have similar (though not necessarily equal) weights, but at the same time their respective values can differ a lot, based on how fine the gold is. Formally, every gold bar has two characteristics: its weight wi and its value vi, where the difference between the weights of the lightest and the heaviest bars does not exceed 3. Luckily for them, Fred's trained eyes can measure the value of any gold bar immediately. There is a problem though: the members of the gang — even though they trained hard — have a combined strength of W, meaning that they can carry at most W units of weight in total. This capacity may not be enough to take every gold bar with them, so your task is to help them determine the maximum total value of gold bars they can steal, provided the total weight of the stolen bars does not exceed W. Input SpecificationThe first line of the input contains the number of gold bars N (1 ≤ N ≤ 100) and the combined strength of the gang W (1 ≤ W ≤ 109). Each of the next N lines contains two integers wi and vi, describing one of the gold bars (1 ≤ wi ≤ 109, 1 ≤ vi ≤ 107). The difference between the highest and lowest weights wmax and wmin is at most 3, i.e., wmax ≤ wmin + 3. Output SpecificationPrint a single line containing the highest total value of gold bars they can steal, provided the total weight of the stolen bars does not exceed W. Sample Input 1
Output for Sample Input 1
Sample Input 2
Output for Sample Input 2
Sample Input 3
Output for Sample Input 3
In the first example, they can steal the first and the third bar, as their total weight is 2 + 4 = 6. In this case, the total value of the stolen bars is 1 + 10 = 11. |
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |