Number of Coins
Submissions: 21400   Accuracy:


  Difficulty: Medium   Marks: 4

Given a value V. You have to make change for V cents, given that you have infinite supply of each of C{ C1, C2, .. , Cm} valued coins. Find the minimum number of coins to make the change.

The first line of input contains an integer T denoting the number of test cases. The first line of each test case is V and N, V is the value of cents and N is the number of coins. The second line of each test case contains N input C[i], value of available coins.

Print the minimum number of coins to make the change, if not possible print "-1".

1 ≤ T ≤ 100
1 ≤ V ≤ 106
1 ≤ N ≤ 106
1 ≤ C[i] ≤ 106

7 2
2 1


Explanation :
Testcase 1:
We can use coin with value 2 three times, and coin with value 1 one times to change a total of 7.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shikhar

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.