欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2096B.Wonderful Gloves
Wonderful Gloves
You are the proud owner of many colorful gloves, and you keep them in a drawer. Each glove is in one of colors numbered to . Specifically, for each from to , you have left gloves and right gloves with color .
Unfortunately, it's late at night, so you can't see any of your gloves. In other words, you will only know the color and the type (left or right) of a glove after you take it out of the drawer.
A matching pair of gloves with color consists of exactly one left glove and one right glove with color . Find the minimum number of gloves you need to take out of the drawer to guarantee that you have at least matching pairs of gloves with different colors.
Formally, find the smallest positive integer such that:
- For any set of gloves you take out of the drawer, there will always be at least matching pairs of gloves with different colors.
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 of each test case contains two integers , () — the number of different colors, and the minimum number of required matching pairs of gloves.
The second line of each test case contains integers () — the number of left gloves with color for each from to .
The third line of each test case contains integers () — the number of right gloves with color for each from to .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the minimum number of gloves you need to take out of the drawer.
Note
In the first test case, you must take out all of the gloves, so the answer is .
In the second test case, the answer is . If you take out gloves or fewer, then it is possible that all of them are left gloves, which means you won't have a matching pair of gloves.
In the third test case, the answer is . If you only take out gloves, then one possible scenario is as follows:
- Color : left gloves, right gloves
- Color : left glove, right gloves
- Color : left gloves, right glove
You only have multiple matching pairs of gloves with color . So you won't have at least matching pairs of gloves with different colors.
Samples
5
3 3
1 1 1
1 1 1
1 1
100
1
3 2
100 1 1
200 1 1
5 2
97 59 50 87 36
95 77 33 13 74
10 6
97 59 50 87 36 95 77 33 13 74
91 14 84 33 54 89 68 34 14 15
6
101
303
481
1010
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |