LKP '18 Contest 1 P1 - World Trade Foundation

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type

The World Trade Foundation has N denominations of coins, a1,a2,,aN where ai is a multiple of ai1 for 2iN. The WTF wishes to perform a transaction that costs exactly K Quunar (the local currency). Because they value efficiency over all else, determine the minimum number of coins they need to get exactly K Quunar, or print -1 if this is not possible.

Constraints

1N10
1ai109
1K109
It is guaranteed that ai is a multiple of ai1.

Input Specification

On the first line, there are two space-separated integers, N K.
The next line contains N space-separated integers, ai, the values of the coins (in Quunar).

Output Specification

On one line, output the minimum number of coins needed to make a sum of exactly K Quunar or print -1 if this is not possible.

Sample Input 1

Copy
3 10
1 2 4

Sample Output 1

Copy
3

Sample Input 2

Copy
5 263
1 5 10 50 100

Sample Output 2

Copy
7

Sample Input 3

Copy
3 7
2 6 12

Sample Output 3

Copy
-1

Comments


  • 6
    IanHu  commented on Dec. 17, 2018, 2:10 a.m.

    World Trade Foundation = WTF ?????