#C11923. Minimum Number of Gifts
Minimum Number of Gifts
Minimum Number of Gifts
You are given several test cases. For each test case, you have n gifts with corresponding prices and q queries. In each query, you are given a target total price x. Your task is to compute the minimum number of gifts required such that the sum of their prices is at least x. You must choose the gifts in descending order of their prices to minimize the number of gifts used. If it is impossible to reach the target price for a query, output \( -1 \).
Input Format: The input begins with an integer T representing the number of test cases. Each test case is described as follows:
- The first line contains two integers, n and q, where n is the number of available gifts and q is the number of queries.
- The second line contains n space-separated integers, representing the prices of the gifts.
- The third line contains q space-separated integers, each a target total price.
Output Format: For each query, print the minimum number of gifts required on a separate line. If it is impossible to reach the target sum from the available gifts, print \( -1 \).
Constraints: The values of n, q, gift prices, and queries will be such that a solution can be computed efficiently.
inputFormat
The first line of input contains a single integer T representing the number of test cases. For each test case, the first line contains two integers n and q. The next line contains n integers indicating the prices of the gifts, and the following line contains q integers representing the query targets.
outputFormat
For each query in each test case, output a single integer on a new line denoting the minimum number of gifts needed to achieve at least the target price. If it is impossible, output \( -1 \).
## sample1
6 2
5 4 2 6 3 1
10 3
2
1
</p>