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

#GD0000239. Nhận dạng thuật toán: Chọn vật trong ba lô (Mixed Greedy Recognition 02)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Nhận dạng thuật toán: Chọn vật trong ba lô (Mixed Greedy Recognition 02)

Mixed Greedy Recognition 02

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn items. Item ii has weight wiw_i and value viv_i. Your knapsack can carry total weight at most WW. Each item can be selected at most once and cannot be split.

Find the maximum total value of a feasible subset. You need not fill the capacity and may choose no items.

Input

  • The first line contains n,Wn,W.
  • Each of the next nn lines contains wi,viw_i,v_i for an item.

Output

Print the maximum total value that can be placed in the knapsack.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤W≤50000\le W\le 5000; 1≤wi≤50001\le w_i\le 5000; 1≤vi≤1061\le v_i\le 10^6.
  • Subtask 2 (30 points): 1≤n≤301\le n\le 30; 0≤W≤50000\le W\le 5000; 1≤wi≤50001\le w_i\le 5000; 1≤vi≤1061\le v_i\le 10^6.
  • Subtask 3 (50 points): 1≤n≤1001\le n\le 100; 0≤W≤50000\le W\le 5000; 1≤wi≤50001\le w_i\le 5000; 1≤vi≤1061\le v_i\le 10^6.

Examples

Input

4 7
3 4
4 5
2 3
5 7

Output

10

Explanation

Items 33 and 44 have total weight 2+5=72+5=7 and value 3+7=103+7=10. Items 11 and 22 also fit but give value 4+5=94+5=9. No feasible subset exceeds 1010, so print 1010.