309422: CF1676E. Eating Queries
Memory Limit:256 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:23
Solved:0
Description
Eating Queries
题意翻译
有 $n$ 颗糖,吃第 $i$ 颗糖可以得到 $a_i$ 的糖分。 有 $q$ 次询问,每次询问最少吃多少颗糖可以得到不小于 $x$ 的糖分,无解输出 `-1`。 注意:在每次询问中,不能多次吃同一颗糖;每次询问互相独立,即不同询问可以吃同一颗糖。题目描述
Timur has $ n $ candies. The $ i $ -th candy has a quantity of sugar equal to $ a_i $ . So, by eating the $ i $ -th candy, Timur consumes a quantity of sugar equal to $ a_i $ . Timur will ask you $ q $ queries regarding his candies. For the $ j $ -th query you have to answer what is the minimum number of candies he needs to eat in order to reach a quantity of sugar greater than or equal to $ x_j $ or print -1 if it's not possible to obtain such a quantity. In other words, you should print the minimum possible $ k $ such that after eating $ k $ candies, Timur consumes a quantity of sugar of at least $ x_j $ or say that no possible $ k $ exists. Note that he can't eat the same candy twice and queries are independent of each other (Timur can use the same candy in different queries).输入输出格式
输入格式
The first line of input contains a single integer $ t $ ( $ 1 \leq t \leq 1000 $ ) — the number of test cases. The description of test cases follows. The first line contains $ 2 $ integers $ n $ and $ q $ ( $ 1 \leq n, q \leq 1.5\cdot10^5 $ ) — the number of candies Timur has and the number of queries you have to print an answer for respectively. The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \leq a_i \leq 10^4 $ ) — the quantity of sugar in each of the candies respectively. Then $ q $ lines follow. Each of the next $ q $ lines contains a single integer $ x_j $ ( $ 1 \leq x_j \leq 2 \cdot 10^9 $ ) – the quantity Timur wants to reach for the given query. It is guaranteed that the sum of $ n $ and the sum of $ q $ over all test cases do not exceed $ 1.5 \cdot 10^5 $ .
输出格式
For each test case output $ q $ lines. For the $ j $ -th line output the number of candies Timur needs to eat in order to reach a quantity of sugar greater than or equal to $ x_j $ or print -1 if it's not possible to obtain such a quantity.
输入输出样例
输入样例 #1
3
8 7
4 3 3 1 1 4 5 9
1
10
50
14
15
22
30
4 1
1 2 3 4
3
1 2
5
4
6
输出样例 #1
1
2
-1
2
3
4
8
1
1
-1