~/algor $ cat problems/dp-eng-kam-tangalar
Fewest coins
Medium
1000 ms
128 MB
47%
There are coins of $n$ different denominations: $c_{1}, c_{2}, \dots, c_{n}$; any number of coins of each denomination may be taken. Find the smallest number of coins that add up to exactly $S$ soums. If $S$ cannot be made, print $-1$.
Input
The first line contains two integers: $n$ and $S$. The second line contains $n$ distinct positive integers $c_{j}$.
Output
One integer — the smallest number of coins or $-1$.
Note
$1 \le n \le 50$
$0 \le S \le 10^{4}$
$1 \le c_{j} \le 10^{4}$
Examples
Input #1
3 11 1 2 5
Output #1
3
Input #2
2 3 2 4
Output #2
-1