欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1453A.Cancel the Trains
Cancel the Trains
Gildong's town has a train system that has trains that travel from the bottom end to the top end and trains that travel from the left end to the right end. The trains starting from each side are numbered from to , respectively, and all trains have the same speed. Let's take a look at the picture below.

The train system can be represented as coordinates on a 2D plane. The -th train starting at the bottom end is initially at and will be at after minutes, and the -th train starting at the left end is initially at and will be at after minutes. All trains arrive at their destinations after minutes.
However, Gildong found that some trains scheduled to depart at a specific time, simultaneously, are very dangerous. At this time, trains are scheduled to depart from the bottom end and trains are scheduled to depart from the left end. If two trains are both at at the same time for some and , they will crash into each other. Therefore, he is asking you to find the minimum number of trains that should be cancelled to prevent all such crashes.
Input
Each test contains one or more test cases. The first line contains the number of test cases ().
Each test case contains three lines. The first line of each test case consists of two integers and () — the number of trains scheduled to depart from the bottom end, and the number of trains scheduled to depart from the left end, respectively.
The second line of each test case contains integers. Each integer is a train number that is scheduled to start from the bottom end. The numbers are given in strictly increasing order, and are between and , inclusive.
The third line of each test case contains integers. Each integer is a train number that is scheduled to start from the left end. The numbers are given in strictly increasing order, and are between and , inclusive.
Output
For each test case, print a single integer: the minimum number of trains that should be canceled in order to prevent all crashes.
Note
In the first case, we can show that there will be no crashes if the current schedule is followed. Therefore, the answer is zero.
In the second case, at , there will be a crash, as can be seen in the picture below. We can prove that after canceling one of these trains, the remaining trains will not crash. Therefore, the answer is one.

Samples
3
1 2
1
3 4
3 2
1 3 4
2 4
9 14
2 7 16 28 33 57 59 86 99
3 9 14 19 25 26 28 35 41 59 85 87 99 100
0
1
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |