Fewest Coins
Coins of the given denominations are available in unlimited supply. Print the minimum number of coins summing exactly to T, or −1 if impossible.
Input: the first line has N and T; the second line has the N denominations.
Output: the minimum coin count, or −1.
Constraints:
- 1 ≤ N ≤ 12
- 0 ≤ T ≤ 104
- 1 ≤ ci ≤ 100
Sample Tests
Input 1
3 6 1 3 4
Output 1
2
Input 2
1 3 2
Output 2
-1
Discussion (opens after you solve — no spoilers before)
No comments yet.