#CT0000077. Chọn quà (Gift Selection)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Chọn quà (Gift Selection)
Gift Selection
Version: Phuoc Hung OJ Extended
Problem Statement
There are gifts numbered from to . Gift has weight and value . A bag has capacity : the total weight of the chosen gifts must not exceed .
Choose a subset of gifts such that:
- Each gift is selected at most once.
- The total weight does not exceed .
- The total value is maximized.
Choosing no gifts is allowed; the empty selection has total weight and total value equal to .
Input
Line 1 contains integers , .
Each of the next lines contains integers , describing gift .
Output
Output one integer: the maximum total value.
Subtasks
- Subtask 1 (25 points): ; ; , for every .
- Subtask 2 (35 points): ; ; , for every .
- Subtask 3 (40 points): ; ; , for every .
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.
Liên quan
Trong các cuộc thi sau: