Problem list
Log in
#r03336 · Online Judge > GoldOJ

Unbounded Knapsack

Gold V 2.0 s 256 MB

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
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code