PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000041. Ba lô 2 (Knapsack 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ba lô 2 (Knapsack 2)

Knapsack 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You have nn items, where item ii has weight wiw_i and value viv_i. The knapsack capacity WW can be very large, whereas individual values are comparatively small. Each item may be used at most once. Find the maximum attainable value without exceeding total weight WW.

Input

The first line contains nn and WW, followed by nn lines containing wiw_i and viv_i.

Output

Print the maximum total value of the chosen items.

Subtasks

The independent scoring groups have the following complete constraints:

  • Subtask 1 (20%): 1≤n≤81\le n\le 8, 1≤W≤10001\le W\le 1000, 1≤wi≤W1\le w_i\le W, 1≤vi≤301\le v_i\le 30.
  • Subtask 2 (30%): 1≤n≤351\le n\le 35, 1≤W≤10000001\le W\le 1000000, 1≤wi≤W1\le w_i\le W, 1≤vi≤1001\le v_i\le 100.
  • Subtask 3 (50%): 1≤n≤1001\le n\le 100, 1≤W≤10000000001\le W\le 1000000000, 1≤wi≤W1\le w_i\le W, 1≤vi≤10001\le v_i\le 1000.

Examples

Input

3 8
3 30
4 50
5 60

Output

90

Explanation

Choose items 1 and 3: weight 88 and value 9090. Taking only item 3 yields 6060, so the optimal value is 9090.