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
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.