CF1927C.Choose the Different Ones!

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an array aa of nn integers, an array bb of mm integers, and an even number kk.

Your task is to determine whether it is possible to choose exactly k2\frac{k}{2} elements from both arrays in such a way that among the chosen elements, every integer from 11 to kk is included.

For example:

  • If a=[2,3,8,5,6,5]a=[2, 3, 8, 5, 6, 5], b=[1,3,4,10,5]b=[1, 3, 4, 10, 5], k=6k=6, then it is possible to choose elements with values 2,3,62, 3, 6 from array aa and elements with values 1,4,51, 4, 5 from array bb. In this case, all numbers from 11 to k=6k=6 will be included among the chosen elements.
  • If a=[2,3,4,5,6,5]a=[2, 3, 4, 5, 6, 5], b=[1,3,8,10,3]b=[1, 3, 8, 10, 3], k=6k=6, then it is not possible to choose elements in the required way.

Note that you are not required to find a way to choose the elements — your program should only check whether it is possible to choose the elements in the required way.

给定一个包含 nn 个整数的数组 aa、一个包含 mm 个整数的数组 bb,以及一个偶数 kk。

你的任务是判断:是否能分别从两个数组中恰好各选出 k2\frac{k}{2} 个元素,使得所有被选出的元素中,恰好包含 11 到 kk 中的每一个整数(即集合 {1,2,…,k}\{1,2,\dots,k\} 是所选元素值的子集)。

例如:

  • 若 a=[2,3,8,5,6,5]a=[2, 3, 8, 5, 6, 5],b=[1,3,4,10,5]b=[1, 3, 4, 10, 5],k=6k=6,则可以从数组 aa 中选出值为 2,3,62, 3, 6 的元素,从数组 bb 中选出值为 1,4,51, 4, 5 的元素。此时,所有从 11 到 k=6k=6 的整数均出现在所选元素中。
  • 若 a=[2,3,4,5,6,5]a=[2, 3, 4, 5, 6, 5],b=[1,3,8,10,3]b=[1, 3, 8, 10, 3],k=6k=6,则无法按要求选出元素。

注意:你无需构造具体的选取方案——你的程序只需判断是否存在满足要求的选取方式。

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The descriptions of the test cases follow.

The first line of each test case contains three integers nn, mm, and kk (1≤n,m≤2⋅1051 \le n, m \le 2\cdot10^5, 2≤k≤2⋅min⁡(n,m)2 \le k \le 2 \cdot \min(n, m), kk is even) — the length of array aa, the length of array bb, and the number of elements to be chosen, respectively.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061 \le a_i \le 10^6) — the elements of array aa.

The third line of each test case contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bj≤1061 \le b_j \le 10^6) — the elements of array bb.

It is guaranteed that the sum of values nn and mm over all test cases in a test does not exceed 4⋅1054 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(1≤n,m≤2⋅1051 \le n, m \le 2\cdot10^5,2≤k≤2⋅min⁡(n,m)2 \le k \le 2 \cdot \min(n, m),且 kk 为偶数),分别表示数组 aa 的长度、数组 bb 的长度以及需选取的元素个数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6),表示数组 aa 的元素。

每个测试用例的第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bj≤1061 \le b_j \le 10^6),表示数组 bb 的元素。

保证所有测试用例中 nn 与 mm 的总和不超过 4⋅1054 \cdot 10^5。

输出格式

Output tt lines, each of which is the answer to the corresponding test case. As the answer, output "YES" if it is possible to choose k2\frac{k}{2} numbers from each array in such a way that among the chosen elements, every integer from 11 to kk is included. Otherwise, output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

输出 tt 行,每行对应一个测试用例的答案。若能从每个数组中各选出 k2\frac{k}{2} 个数,使得所选元素恰好包含 11 到 kk 中的每一个整数,则输出 "YES";否则输出 "NO"。

每个字母可为任意大小写(小写或大写)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为有效的肯定回答。

输入输出样例

  • 输入#1

    6
    6 5 6
    2 3 8 5 6 5
    1 3 4 10 5
    6 5 6
    2 3 4 5 6 5
    1 3 8 10 3
    3 3 4
    1 3 5
    2 4 6
    2 5 4
    1 4
    7 3 4 4 2
    1 4 2
    2
    6 4 4 2
    1 5 2
    3
    2 2 1 4 3

    输出#1

    YES
    NO
    YES
    YES
    NO
    NO

说明/提示

In the first test case of the example, it is possible to choose elements equal to 22, 33, and 66 from array aa and elements equal to 11, 44, and 55 from array bb. Thus, all numbers from 11 to k=6k=6 are included among the chosen elements.

In the second test case of the example, it can be shown that it is not possible to choose exactly three elements from each array in the required way.

In the third test case of the example, it is possible to choose elements equal to 11 and 33 from array aa and elements equal to 22 and 44 from array bb. Thus, all numbers from 11 to k=4k=4 are included among the chosen elements.

在示例的第一个测试用例中,可以从数组 aa 中选择值为 22、33 和 66 的元素,并从数组 bb 中选择值为 11、44 和 55 的元素。因此,所选元素中包含了从 11 到 k=6k=6 的所有整数。

在示例的第二个测试用例中,可以证明:无法按要求的方式,恰好从每个数组中各选出三个元素。

在示例的第三个测试用例中,可以从数组 aa 中选择值为 11 和 33 的元素,并从数组 bb 中选择值为 22 和 44 的元素。因此,所选元素中包含了从 11 到 k=4k=4 的所有整数。

输入解题思路,AI测评打分。不知道怎么写?

首页