buying roses

4

1 votes
Easy
Problem

Vishi aka Chottu is a shy boy of NITH. On this hill'ffair he decided to give roses to his crush . His friend cheema persuaded him to give her n roses as n is her favourite number . English club (club which sells roses on high cost on hill'ffair :P) has a wierd rule . They are selling roses in bunches . There are k type of bunches . They have plenty of bunches of each type . And each type of bunch contains different number of roses. Each bunch is of same price 10$. As vishi is miser , he wants to minimize the cost . Help him in selecting bunches
You are provided an array A of k numbers describing the size of bunches available . You are to buy some bunches so that total number of roses in all those bunches is n. help him to decide how to buy those roses .

INPUT

First line of input containg t number of test cases First line of each test case includes two numbers n and k . Next line contains k space seperated integers defining size of bunches available.

OUTPUT

CONSTRAINTS

1<=t<=10
1<=n<=5000
1<=k<=1000000
1<=A[i]<=1000000

You are to print minimum expenditure of vishi . If it is not possible to buy n number of roses , then print -1 .

Sample Input
2
8 3
1 2 4
3 5
1 2 3 4 5
Sample Output
20
10
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

in 1 test case vishi can buy 2 bunches of size 4 to get total 8 roses . in test case 2 vishi can buy 1 bunch of size 3 in test case 3 there is no way to buy 5 roses

Editor Image

?