欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1629A.Download More RAM
Download More RAM
Did you know you can download more RAM? There is a shop with different pieces of software that increase your RAM. The -th RAM increasing software takes GB of memory to run (temporarily, once the program is done running, you get the RAM back), and gives you an additional GB of RAM (permanently). Each software can only be used once. Your PC currently has GB of RAM.
Note that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have.
Since RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable?
Input
The first line of the input contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains the integers and (, ). Then two lines follow, each containing integers describing the arrays and ().
Output
For each test case, output a single line containing the largest amount of RAM you can achieve.
Note
In the first test case, you only have enough RAM to run the third software initially, but that increases your RAM to GB, which allows you to use the first software, increasing your RAM to GB. The only software left needs GB of RAM, so you have to stop here.
In the second test case, you can use the first, second, fourth and fifth software that need only GB of RAM per software to run to increase your RAM to GB, and then use the last remaining one to increase your RAM to GB.
In the third test case, all the software need more than GB of RAM to run, so the amount of RAM you have stays at GB.
Samples
4
3 10
20 30 10
9 100 10
5 1
1 1 5 1 1
1 1 1 1 1
5 1
2 2 2 2 2
100 100 100 100 100
5 8
128 64 32 16 8
128 64 32 16 8
29
6
1
256
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |