You have an unlimited supply of coins in distinct denominations. Find the minimum number of coins needed to produce the sum exactly.
The first line contains two integers and : the number of denominations and the target sum. The second line contains distinct integers : the coin values.
Print the minimum number of coins needed to produce . If the sum cannot be produced, print .
Input:
3 11
1 5 7
Output:
3
The sum can be produced as , using three coins. It cannot be produced with fewer coins.
Sample 1
Input
3 11 1 5 7
Expected output
3
The sum 11 can be produced as 5 + 5 + 1, using three coins.
| # | User | Language | Solved |
|---|---|---|---|
| 1 | radek | Python | Aug 25, 2026, 10:39 PM |