311145: CF1941A. Rudolf and the Ticket

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:1 Solved:0

Description

A. Rudolf and the Tickettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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 $b_1, b_2, \dots, b_n$. In the right pocket, there are $m$ coins with denominations $c_1, c_2, \dots, c_m$. 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 $b_f + c_s \le k$.

Input

The first line contains an integer $t$ ($1 \le t \le 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 \le n, m \le 100, 1 \le k \le 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 $b_i$ ($1 \le b_i \le 1000$) — the denominations of coins in the left pocket.

The third line of each test case contains $m$ integers $c_i$ ($1 \le c_i \le 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$.

ExampleInput
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
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, 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$.

In the third test case, Rudolf can choose: $[1, 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.

Output

题目大意:
鲁道夫要乘坐地铁去看望伯纳德,他需要在购票机中使用恰好两个硬币,这两个硬币的总和不允许超过 \( k \)。
鲁道夫有两个口袋,左口袋里有 \( n \) 枚硬币,面额分别为 \( b_1, b_2, \dots, b_n \),右口袋里有 \( m \) 枚硬币,面额分别为 \( c_1, c_2, \dots, c_m \)。他需要从左口袋和右口袋中各选择一枚硬币(总共两枚)。
请帮助鲁道夫确定有多少种选择硬币的方式,使得 \( b_f + c_s \le k \)。

输入数据格式:
第一行包含一个整数 \( t \)(\( 1 \le t \le 100 \)),表示测试用例的数量。接下来是每个测试用例的描述。
每个测试用例的第一行包含三个自然数 \( n \), \( m \), \( k \)(\( 1 \le n, m \le 100, 1 \le k \le 2000 \)),分别表示左口袋和右口袋的硬币数量以及购票机接受硬币的最大总和。
每个测试用例的第二行包含 \( n \) 个整数 \( b_i \)(\( 1 \le b_i \le 1000 \)),表示左口袋中硬币的面额。
每个测试用例的第三行包含 \( m \) 个整数 \( c_i \)(\( 1 \le c_i \le 1000 \)),表示右口袋中硬币的面额。

输出数据格式:
对于每个测试用例,输出一个整数,表示鲁道夫可以选择两枚硬币的方式的数量,使得硬币的总和不超过 \( k \)。题目大意: 鲁道夫要乘坐地铁去看望伯纳德,他需要在购票机中使用恰好两个硬币,这两个硬币的总和不允许超过 \( k \)。 鲁道夫有两个口袋,左口袋里有 \( n \) 枚硬币,面额分别为 \( b_1, b_2, \dots, b_n \),右口袋里有 \( m \) 枚硬币,面额分别为 \( c_1, c_2, \dots, c_m \)。他需要从左口袋和右口袋中各选择一枚硬币(总共两枚)。 请帮助鲁道夫确定有多少种选择硬币的方式,使得 \( b_f + c_s \le k \)。 输入数据格式: 第一行包含一个整数 \( t \)(\( 1 \le t \le 100 \)),表示测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含三个自然数 \( n \), \( m \), \( k \)(\( 1 \le n, m \le 100, 1 \le k \le 2000 \)),分别表示左口袋和右口袋的硬币数量以及购票机接受硬币的最大总和。 每个测试用例的第二行包含 \( n \) 个整数 \( b_i \)(\( 1 \le b_i \le 1000 \)),表示左口袋中硬币的面额。 每个测试用例的第三行包含 \( m \) 个整数 \( c_i \)(\( 1 \le c_i \le 1000 \)),表示右口袋中硬币的面额。 输出数据格式: 对于每个测试用例,输出一个整数,表示鲁道夫可以选择两枚硬币的方式的数量,使得硬币的总和不超过 \( k \)。

加入题单

上一题 下一题 算法标签: