Coin Change — Minimum Coins

VERY EASY · C · 2000ms

Vending-machine engineer Sabbir needs the minimum number of coins to dispense any given change amount, from a fixed set of coin types. Given N coin denominations and a target amount X, print the minimum number of coins needed to make exactly X, or -1 if impossible.

Input

Line1: N X. Line2: N denominations.

Output

Minimum coins, or -1.

Constraints

1 ≤ N ≤ 100, 1 ≤ X ≤ 10^4

Sample Input

3 11
1 2 5

Sample Output

3
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Coin Change — Minimum Coins · DIU ContestHub