A knapsack holds total weight at most $W$. There are $N$ gem types, each with weight $w_i$ and value $v_i$, available in unlimited quantity. Print the maximum total value whose total weight does not exceed $W$.
Input
First line $N$ and $W$; then $N$ lines each with $w_i$ and $v_i$ ($1 \le N \le 1000$, $1 \le W \le 10000$, $1 \le w_i \le W$, $1 \le v_i \le 10^6$).
Output
Print the maximum achievable total value.
Example 1
Input
3 10 2 5 3 9 4 11
Output
29
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.