Sign in $ create-account
~/problems ~/discussion ~/contests ~/submission
← ~/problems
P2019

Coin Change

Medium
// Description
Given coin denominations and a target amount, output the minimum number of coins needed to make the amount, or -1 if it is impossible. Each coin may be used any number of times.
// Input
The first line contains the amount A and the number of coin types C (0 <= A <= 10^4, 1 <= C <= 20). The second line contains C coin values.
// Output
The minimum number of coins, or -1 if the amount cannot be formed.
// Hint
Unbounded-knapsack style DP over the amount.
// Samples
Sample Input
11 3
1 2 5
Sample Output
3
// Problem Info
DifficultyMedium
Acceptance40%
Time Limit1000 ms
Memory Limit65536 KB
Accepted4