Coin Change (Fewest Coins)
Using unlimited coins of the given values, make exactly with as few coins as possible. Print -1 if impossible. (Greedy fails for values like 1, 3, 4 and .)
Input
, then the coin values, then .
Output
The minimum number of coins or -1.
Constraints
, coin ,
Sample 1
Input
3 1 3 4 6
Output
2
Sample 2
Input
1 2 3
Output
-1