Problem list
Log in
#r03205 · Online Judge > GoldOJ

Coin Change (Canonical)

Silver IV 2.0 s 1024 MB

There are $N$ coin denominations given in ascending order, where $A_1 = 1$ and each $A_i$ is a multiple of $A_{i-1}$. Using an unlimited supply of each, print the minimum number of coins needed to make exactly $K$ (a greedy from the largest coin is optimal for such a system).

Input

Line 1: $N$ and $K$ ($1 \le N \le 12$, $1 \le K \le 10^8$). Next $N$ lines: the denominations, one per line.

Output

Print the minimum number of coins.

Example 1

Input
5 420
1
5
10
50
100
Output
6

Example 2

Input
3 10
1
2
4
Output
3
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