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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 . There are numbered boats; type takes one unit of space and type takes two units. Boat carries passengers. Select a subset with total volume at most and maximum total passenger capacity. Output the maximum and indices of selected boats.
Input
Line 1 contains . The next lines contain , with 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): ; ; ; for every .
- Subtask 2 (30 points): ; ; ; for every .
- Subtask 3 (50 points): ; ; ; for every .
Examples
Input
3 2
1 2
2 7
1 3
Output
7
2
Explanation
Boat uses both units and carries passengers. Taking boats and instead would carry only . Therefore is optimal, using boat .