欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1941A.Rudolf and the Ticket
Rudolf and the Ticket
Rudolf is going to visit Bernard, and he decided to take the metro to get to him. The ticket can be purchased at a machine that accepts exactly two coins, the sum of which does not exceed .
Rudolf has two pockets with coins. In the left pocket, there are coins with denominations . In the right pocket, there are coins with denominations . He wants to choose exactly one coin from the left pocket and exactly one coin from the right pocket (two coins in total).
Help Rudolf determine how many ways there are to select indices and such that .
Input
The first line contains an integer () — the number of test cases. Then follows the description of each test case.
The first line of each test case contains three natural numbers , , and () — the number of coins in the left and right pockets, and the maximum sum of two coins for the ticket payment at the counter, respectively.
The second line of each test case contains integers () — the denominations of coins in the left pocket.
The third line of each test case contains integers () — the denominations of coins in the right pocket.
Output
For each testcase, output a single integer — the number of ways Rudolf can select two coins, taking one from each pocket, so that the sum of the coins does not exceed .
Note
Note that the pairs indicate the indices of the coins in the array, not their denominations.
In the first test case, Rudolf can choose the following pairs of coins: .
In the second test case, Rudolf cannot choose one coin from each pocket in any way, as the sum of any two elements from the first and second arrays will exceed the value of .
In the third test case, Rudolf can choose: .
In the fourth test case, Rudolf can choose any coin from the left pocket and any coin from the right pocket.
Samples
4
4 4 8
1 5 10 14
2 1 8 1
2 3 4
4 8
1 2 3
4 2 7
1 1 1 1
2 7
3 4 2000
1 1 1
1 1 1 1
6
0
4
12
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |