#GD0000140. Phản ví dụ cho tham lam theo tỉ lệ (0/1 Knapsack Ratio Counterexample)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phản ví dụ cho tham lam theo tỉ lệ (0/1 Knapsack Ratio Counterexample)
0/1 Knapsack Ratio Counterexample
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
You have items of positive integer weights and values , and a 0/1 knapsack with capacity . Consider a hypothetical ratio-greedy algorithm: sort items by decreasing ratio , breaking ties by smaller original index, then accept an item if it fits and skip it otherwise. Output its value, the true optimal 0/1 knapsack value, and whether the ratio-greedy rule fails for the given instance.
Input
The first line contains . Each of the next lines contains .
Output
Print the greedy value and the true optimal value on the first line. On the second line print YES if greedy is worse than optimal, otherwise NO.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
3 50
10 60
20 100
30 120
Output
160 220
YES
Explanation
Ratio-greedy chooses item (weight , value ) and item (weight , value ), totaling . The optimal subset is items and , weight , value . Therefore the rule fails, and YES is printed.