232. Unbounded Knapsack
MediumKnapsack
Each item can be taken any number of times. Print the maximum value with total weight ≤ W.
Input format
Line 1: n W Next n lines: weight value
Output format
The maximum value.
Example 1
Input
2 3 1 1 2 3
Output
4
Example 2
Input
3 8 1 10 3 40 4 50
Output
100
Constraints
1 ≤ n ≤ 100 1 ≤ W ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…