Problems > Fewest Coins

Fewest Coins

Difficulty: 1500 3000 ms 128 MB

dp

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.