Skip to content
UPEEC

0/1 Knapsack

Medium#dynamic-programming· solved by 0 · time limit 2.0 s

You have nn items with weights and values and a bag that holds weight at most WW. Each item can be taken at most once. Maximise the total value.

Input

nn and WW, then nn lines weight value.

Output

The maximum value.

Constraints

1≤n≤1001 \le n \le 100, 1≤W≤1041 \le W \le 10^4

Sample 1

Input

3 4
1 15
3 20
4 30

Output

35

Sign in or join free to run and submit your solution.