A. Rudolf and the Ticket

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 k�.

Rudolf has two pockets with coins. In the left pocket, there are n� coins with denominations b1,b2,...,bn�1,�2,...,��. In the right pocket, there are m� coins with denominations c1,c2,...,cm�1,�2,...,��. 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 f� and s� such that bf+cs≤k��+��≤�.

Input

The first line contains an integer t� (1≤t≤1001≤�≤100) --- the number of test cases. Then follows the description of each test case.

The first line of each test case contains three natural numbers n�, m�, and k� (1≤n,m≤100,1≤k≤20001≤�,�≤100,1≤�≤2000) --- 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 n� integers bi�� (1≤bi≤10001≤��≤1000) --- the denominations of coins in the left pocket.

The third line of each test case contains m� integers ci�� (1≤ci≤10001≤��≤1000) --- 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 k�.

Example

input

Copy

复制代码

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

output

Copy

复制代码
6
0
4
12

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: 1,1,1,2,1,4,2,1,2,2,2,41,1,1,2,1,4,2,1,2,2,2,4.

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 k=4�=4.

In the third test case, Rudolf can choose: 1,1,2,1,3,1,4,11,1,2,1,3,1,4,1.

In the fourth test case, Rudolf can choose any coin from the left pocket and any coin from the right pocket.

解题说明:水题,两个数列每次取一个数相加,遍历判断是否小于k即可。

cpp 复制代码
#include<stdio.h>
int main() 
{
	int p;
	scanf("%d", &p);
	while (p--) 
	{
		int n, m, k, count = 0;
		scanf("%d%d%d", &n, &m, &k);
		int a[102], b[102];
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
		}
		for (int i = 0; i < m; i++)
		{
			scanf("%d", &b[i]);
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++) 
			{
				if (a[i] + b[j] <= k)
				{
					count++;
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}
相关推荐
All for pursuit.6 小时前
【回溯-7】494.目标和
数据结构·c++·算法·leetcode
白杨尚青6 小时前
C++入门篇(十三):vector(上)——动态数组:构造、空间增长与迭代器失效
开发语言·c++·笔记·算法·stl
Jasmine_llq6 小时前
《P17461 [GESP202609 八级] 生成树计数》
算法·栈·tarjan 算法·边双连通分量·深度优先搜索 dfs·tarjan 保存当前路径节点·模乘法
Jasmine_llq6 小时前
《P17462 [GESP202609 八级] 末班车》
算法·dijkstra 算法·最大化版本,求最长可行值·建反向图(逆图 / 反转边)·多源 dijkstra 思想·对每个终点单独跑一遍djst·离线预处理 + 在线查询
the3clipse7 小时前
H.265熵编码核心:CABAC自适应二进制算术编码详解——如何将语法元素高效压缩为比特流
人工智能·算法·视频编码·h.265·hevc·cabac·cavlc
CQU_JIAKE7 小时前
10.4【A】
算法
Godspeed Zhao7 小时前
现代智能雷达技术19——算法(5)
算法
(Charon)7 小时前
【C++面试】RAII到底是什么:从资源管理理解C++对象生命周期
c++·算法·面试
Omics Pro8 小时前
之江实验室NAR|虚拟细胞3阶段训练范式
数据库·人工智能·算法·机器学习·自然语言处理
Tisfy8 小时前
LeetCode 0678.有效的括号字符串:O(n)+O(1)一次遍历
算法·leetcode·字符串·题解·贪心·括号匹配