欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1697B.Promo
Promo
The store sells items, the price of the -th item is . The store's management is going to hold a promotion: if a customer purchases at least items, cheapest of them are free.
The management has not yet decided on the exact values of and . Therefore, they ask you to process queries: for the given values of and , determine the maximum total value of items received for free, if a customer makes one purchase.
Note that all queries are independent; they don't affect the store's stock.
Input
The first line contains two integers and () — the number of items in the store and the number of queries, respectively.
The second line contains integers (), where — the price of the -th item.
The following lines contain two integers and each () — the values of the parameters and in the -th query.
Output
For each query, print a single integer — the maximum total value of items received for free for one purchase.
Note
In the first query, a customer can buy three items worth , the two cheapest of them are .
In the second query, a customer can buy two items worth and , the cheapest of them is .
In the third query, a customer has to buy all the items to receive the three cheapest of them for free; their total price is .
Samples
5 3
5 3 1 5 2
3 2
1 1
5 3
8
5
6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |