Problem list
Log in
#r03206 · Online Judge > GoldOJ

Coin Change (General)

Gold V 2.0 s 1024 MB

There are $N$ coin denominations (arbitrary positive integers). Using an unlimited supply of each, print the minimum number of coins needed to make exactly $K$, or -1 if it is impossible.

Input

Line 1: $N$ and $K$ ($1 \le N \le 100$, $1 \le K \le 10000$). Line 2: $N$ denominations ($1 \le A_i \le 10000$).

Output

Print the minimum number of coins, or -1.

Example 1

Input
3 6
1 3 4
Output
2

Example 2

Input
2 7
3 5
Output
-1
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code