Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-yukxalta

Knapsack

Medium 1000 ms 128 MB 53%
Share

A bag can hold at most $W$ kg. There are $n$ items: the weight of the $i$-th item is $w_{i}$ kg and its value is $v_{i}$. Items cannot be divided, and each is taken at most once. Find the largest total value of the items in the bag.

The most valuable set of items that fits into the bag

Input

The first line contains two positive integers: $n$ and $W$. Each of the next $n$ lines contains two positive integers: $w_{i}$ and $v_{i}$.

Output

One integer — the largest total value.

Note

$1 \le n \le 100$
$1 \le W \le 10^{4}$
$1 \le w_{i} \le 10^{4}$
$1 \le v_{i} \le 10^{6}$

Examples

Input #1
4 7
1 1
3 4
4 5
5 7
Output #1
9
Input #2
2 3
5 10
4 20
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.