There are $N$ items, the $i$-th item has a weight of $w_i$ and a value of $v_i$. You have a bag of capacity $W$, meaning you can only take items with sum of weights less than $W$. Choose some items to put into the bag such that the sum of values of the items is maximised, and the bag does not break.
Formally, choose $$\{i_1, i_2, \dots, i_K \} \subseteq \{1, 2, \dots, N \}$$ such that $$\sum_{j=1}^K w_{i_j} \le W$$ and maximises $$V=\sum_{j=1}^K v_{i_j}.$$
Input
The first line of input contains two integers, $N$ and $W$. The following $N$ lines of input contains two integers each, $w_i$ and $v_i$.
Output
Output a single integer, the maximum sum of values of the items.
Constraints
$1 \le N \le 100$
$1 \le W \le 10^9$
$1 \le w_i \le W$
$1 \le v_i \le 1000$
Sample Test Cases
Input | Output | |
---|---|---|
3 8 3 30 4 50 5 60 |
90 | |
1 1000000000 1000000000 10 |
10 | |
6 15 6 5 5 6 6 4 6 6 3 5 7 2 |
17 |
Scoring: Per Subtask
Authored by s17r28
Appeared in 2023 DP Contest