欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2143B.Discounts
Discounts
You want to buy products with prices . You can either:
- buy product individually, paying coins, or
- use a discount voucher to buy it as part of a group purchase.
You have discount vouchers with values . A voucher of value allows you to select exactly products and pay only for the most expensive ones, as such, you can consider that the cheapest product in the group is free. Each product can be included in at most one discount group, even if it is not the free one. Also, any single voucher can be used at most one single time.
What is the minimum total cost required to purchase all products?
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line contains two integers and () —the number of products and the number of available discount vouchers.
The second line contains integers () — the prices of the products.
The third line contains integers () — the values of the discount vouchers.
It is guaranteed that the sum of across all test cases does not exceed , and the sum of across all test cases does not exceed .
Output
Print lines. The -th line should contain the answer for the -th test case — the minimum total cost required to purchase all products in that test case.
Note
In the first test case, you can apply the first discount to products 2, 3, and 4. You will pay for the two most expensive ones (3 and 7 coins) and get the cheapest one for free, resulting in a cost of coins. Then, apply the second and third discounts to products 1 and 5, getting both for free. The total cost is coins.
In the second test case, you can use the single discount on products 2, 3, 4, 5, and 6. Among them, the cheapest is product 2 (costing 2 coins), which you get for free. You pay for the remaining products: coins in total.
In the third test case, only one discount is available. You can use it on both products, getting the cheaper one for free and paying coin for the other.
Samples
5
5 3
18 3 7 2 9
3 1 1
6 1
1 2 6 3 3 4
5
2 3
1 1
2 2 2
1 1
10
1
5 3
99 99 999 999 123
2 1 4
10
17
1
0
1197
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |