#GD0000017. Phản ví dụ đổi tiền tham lam (Coin Change Counterexample)
Phản ví dụ đổi tiền tham lam (Coin Change Counterexample)
Coin Change Counterexample
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given distinct positive coin denominations including , and a target , with unlimited supply of every coin. The greedy algorithm repeatedly takes the largest coin not exceeding the remaining amount. Compute the greedy coin count and the true optimal coin count, then report whether greedy fails on this instance.
Input
The first line contains . The second line contains distinct denominations.
Output
Line 1 prints the greedy coin count. Line 2 prints the optimal coin count. Line 3 prints FAIL if greedy uses more coins than optimal, otherwise OK.
Subtasks
General constraints:
-
.
-
.
-
.
-
The are distinct and one denomination equals .
-
Subtask 1 (20 points): ,
-
Subtask 2 (30 points): ,
-
Subtask 3 (50 points): No additional constraints.
Examples
Input
3 6
1 3 4
Output
3
2
FAIL
Explanation
Greedy uses , so it needs coins. The optimum is , which uses . Since , the result is FAIL.