#GD0000018. Tham lam và DP - Đổi tiền (Greedy vs DP - Coin Change)
Tham lam và DP - Đổi tiền (Greedy vs DP - Coin Change)
Greedy vs DP - Coin Change
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given distinct positive coin denominations including and a limit , compare largest-coin-first greedy with the true minimum number of coins for every amount from through . Find the smallest amount where greedy fails, or print -1 if none exists in the range.
Input
The first line contains . The second line contains distinct denominations.
Output
If a counterexample exists, print the smallest , the greedy count, and the optimal count. Otherwise print -1.
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 20
1 3 4
Output
6 3 2
Explanation
For amounts through , greedy is still optimal. At , greedy uses (three coins) while the optimum is (two coins), so is the smallest counterexample.