欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1676E.Eating Queries
Eating Queries
Timur has candies. The -th candy has a quantity of sugar equal to . So, by eating the -th candy, Timur consumes a quantity of sugar equal to .
Timur will ask you queries regarding his candies. For the -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 or print -1 if it's not possible to obtain such a quantity. In other words, you should print the minimum possible such that after eating candies, Timur consumes a quantity of sugar of at least or say that no possible 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).
Input
The first line of input contains a single integer () — the number of test cases. The description of test cases follows.
The first line contains integers and () — the number of candies Timur has and the number of queries you have to print an answer for respectively.
The second line contains integers () — the quantity of sugar in each of the candies respectively.
Then lines follow.
Each of the next lines contains a single integer () – the quantity Timur wants to reach for the given query.
It is guaranteed that the sum of and the sum of over all test cases do not exceed .
Output
For each test case output lines. For the -th line output the number of candies Timur needs to eat in order to reach a quantity of sugar greater than or equal to or print -1 if it's not possible to obtain such a quantity.
Note
For the first test case:
For the first query, Timur can eat any candy, and he will reach the desired quantity.
For the second query, Timur can reach a quantity of at least by eating the -th and the -th candies, thus consuming a quantity of sugar equal to .
For the third query, there is no possible answer.
For the fourth query, Timur can reach a quantity of at least by eating the -th and the -th candies, thus consuming a quantity of sugar equal to .
For the second test case:
For the only query of the second test case, we can choose the third candy from which Timur receives exactly sugar. It's also possible to obtain the same answer by choosing the fourth candy.
Samples
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
2
-1
2
3
4
8
1
1
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |