Coin Change - Minimum Coins
Given coin denominations, find the minimum number of coins to make a target amount.
Input format
The first line contains N and AMOUNT. The second line contains N arbitrary coin denominations.
Output format
Print the minimum number of coins, or -1 if impossible.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
3 82
44 4 14Expected output
8Example 2
Input
6 15
11 15 37 27 24 50Expected output
1