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

#CT0000077. Chọn quà (Gift Selection)

Bài tập này chưa được xếp vào lộ trình.

Chọn quà (Gift Selection)

Gift Selection

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn gifts numbered from 11 to nn. Gift ii has weight wiw_i and value viv_i. A bag has capacity WW: the total weight of the chosen gifts must not exceed WW.

Choose a subset of gifts such that:

  • Each gift is selected at most once.
  • The total weight does not exceed WW.
  • The total value is maximized.

Choosing no gifts is allowed; the empty selection has total weight and total value equal to 00.

Input

Line 1 contains integers nn, WW.

Each of the next nn lines contains integers wiw_i, viv_i describing gift ii.

Output

Output one integer: the maximum total value.

Subtasks

  • Subtask 1 (25 points): 1≤n≤181 \le n \le 18; 1≤W≤150001 \le W \le 15000; 1≤wi≤150001 \le w_i \le 15000, 1≤vi≤1091 \le v_i \le 10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (35 points): 1≤n≤1201 \le n \le 120; 1≤W≤5001 \le W \le 500; 1≤wi≤150001 \le w_i \le 15000, 1≤vi≤1091 \le v_i \le 10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (40 points): 1≤n≤1201 \le n \le 120; 1≤W≤150001 \le W \le 15000; 1≤wi≤150001 \le w_i \le 15000, 1≤vi≤1091 \le v_i \le 10^9 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

4 7
3 5
4 6
2 4
5 7

Output

11

Explanation: Choose items 1 and 2, with weights 3 and 4 and values 5 and 6. Total weight is 7 and total value is 11; no feasible selection is better.

Example 2

Input

3 5
4 10
5 13
2 6

Output

13

Explanation: Capacity is 5. Item 2 alone has weight 5 and value 13. Other individual items have values 10 and 6; no two items fit together.

Example 3

Input

2 1
2 100
3 200

Output

0

Explanation: Both items are heavier than capacity 1, so the only feasible selection is empty and its value is 0.