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

#QHD0000040. Ba lô 1 (Knapsack 1)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ba lô 1 (Knapsack 1)

Knapsack 1

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Taro has nn distinct items numbered from 11 to nn. Item ii has weight wiw_i and value viv_i. His knapsack can carry total weight at most WW. Each item can be selected at most once, and choosing no item is allowed. Determine the greatest possible total value subject to the weight limit.

Input

The first line contains nn and WW. Each of the following nn lines contains wiw_i and viv_i.

Output

Print one integer: the maximum total value.

Subtasks

The independent scoring groups have the following complete constraints:

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

Examples

Input

3 8
3 30
4 50
5 60

Output

90

Explanation

Select items 1 and 3: their combined weight is 3+5=83+5=8, and total value is 30+60=9030+60=90. Items 2 and 3 together weigh 99, which exceeds capacity. The optimum is 9090.