Skip to content
UPEEC

Coin Change (Fewest Coins)

Medium#dynamic-programming· solved by 0 · time limit 2.0 s

Using unlimited coins of the given values, make exactly xx with as few coins as possible. Print -1 if impossible. (Greedy fails for values like 1, 3, 4 and x=6x = 6.)

Input

nn, then the nn coin values, then xx.

Output

The minimum number of coins or -1.

Constraints

1≤n≤1001 \le n \le 100, 1≤1 \le coin ≤104\le 10^4, 0≤x≤1040 \le x \le 10^4

Sample 1

Input

3
1 3 4
6

Output

2

Sample 2

Input

1
2
3

Output

-1

Sign in or join free to run and submit your solution.