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

#GD0000106. Chọn thuyền lên xe tải (Lorry)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chọn thuyền lên xe tải (Lorry)

Lorry

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A lorry has volume capacity vv. There are nn numbered boats; type 11 takes one unit of space and type 22 takes two units. Boat ii carries pip_i passengers. Select a subset with total volume at most vv and maximum total passenger capacity. Output the maximum and indices of selected boats.

Input

Line 1 contains n,vn,v. The next nn lines contain ti,pit_i,p_i, with tit_i the boat type.

Output

Line 1 contains maximum total passenger capacity. Line 2 lists the distinct indices of chosen boats separated by spaces, possibly empty. Any optimum subset is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 1≤v≤1091\le v\le10^9; ti∈{1,2}t_i\in\{1,2\}; 1≤pi≤1041\le p_i\le10^4 for every ii.
  • Subtask 2 (30 points): 1≤n≤25001\le n\le 2500; 1≤v≤1091\le v\le10^9; ti∈{1,2}t_i\in\{1,2\}; 1≤pi≤1041\le p_i\le10^4 for every ii.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤v≤1091\le v\le10^9; ti∈{1,2}t_i\in\{1,2\}; 1≤pi≤1041\le p_i\le10^4 for every ii.

Examples

Input

3 2
1 2
2 7
1 3

Output

7
2

Explanation

Boat 22 uses both units and carries 77 passengers. Taking boats 11 and 33 instead would carry only 2+3=52+3=5. Therefore 77 is optimal, using boat 22.