#QHD0000051. Lặn tìm vàng (Diving for Gold)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lặn tìm vàng (Diving for Gold)
Diving for Gold
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A diver has discovered treasures. Treasure is at depth and contains units of gold. The diver can stay underwater for a total of at most seconds.
Retrieving treasure takes seconds to descend and seconds to ascend, for a total cost of seconds. Each dive brings back at most one treasure and each treasure can be retrieved at most once.
Select a subset of treasures that maximizes the total gold with total diving time at most . Output both the maximum gold and the selected treasures in their original input order. Any optimal selection is accepted.
Input
The first line contains integers . The second line contains . Each of the following lines contains .
Output
Print the maximum total gold, followed by the number of selected treasures. Then print depth-and-gold pairs in the same relative order as in the input. Any optimal solution is accepted.
Subtasks
Scoring groups are independent. All constraints listed for a group apply simultaneously.
- Subtask 1 (20%): , , , , .
- Subtask 2 (30%): , , , , .
- Subtask 3 (50%): , , , , .
Examples
Input
210 4
3
10 5
10 1
7 2
Output
7
2
10 5
7 2
Explanation
Each depth- treasure takes seconds and the depth- treasure takes seconds. Selecting treasures 1 and 3 takes seconds and yields gold, which is optimal.