Online Judge
ProblemsSubmissionsRankingAdmin
Sign in
MC1

Minimizing Coins

Easy★ 1000dynamic programminggreedy
Time limit
1000 ms
Memory limit
256 MB
I/O
stdio
Tests
19 (18 hidden)
Solved by
1

Minimizing Coins

You have an unlimited supply of coins in nnn distinct denominations. Find the minimum number of coins needed to produce the sum xxx exactly.

Input

The first line contains two integers nnn and xxx: the number of denominations and the target sum. The second line contains nnn distinct integers c1,c2,…,cnc_1, c_2, \ldots, c_nc1​,c2​,…,cn​: the coin values.

Output

Print the minimum number of coins needed to produce xxx. If the sum cannot be produced, print −1-1−1.

Constraints

1≤n≤1001 \le n \le 1001≤n≤100

1≤x≤1061 \le x \le 10^61≤x≤106

1≤ci≤1061 \le c_i \le 10^61≤ci​≤106

Example

Input:

text
3 11
1 5 7

Output:

text
3

The sum 111111 can be produced as 5+5+15 + 5 + 15+5+1, using three coins. It cannot be produced with fewer coins.

Samples

Sample 1

Input

3 11
1 5 7

Expected output

3

The sum 11 can be produced as 5 + 5 + 1, using three coins.

Submit a solution

or drop a file onto the editor - up to 2 MB

Log in to submit a solution.

Ranking

#UserLanguageSolved
1radekPythonAug 25, 2026, 10:39 PM