C. Choose the Different Ones!

time limit per test

2 seconds

memory limit per test

256 megabytes

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 k2k2 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.

Input

The first line of the input contains a single integer tt (1≤t≤1041≤t≤104) --- 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≤n,m≤2⋅105, 2≤k≤2⋅min(n,m)2≤k≤2⋅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,...,ana1,a2,...,an (1≤ai≤1061≤ai≤106) --- the elements of array aa.

The third line of each test case contains mm integers b1,b2,...,bmb1,b2,...,bm (1≤bj≤1061≤bj≤106) --- 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⋅105.

Output

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 k2k2 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.

Example

Input

Copy

复制代码

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

Output

Copy

复制代码
YES
NO
YES
YES
NO
NO

Note

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.

解题说明:此题是一道数学题,要从a[i]和b[i]中分别选k/2个元素,以便所选元素包含从 1 到 k 的每个整数。此题采用C++来做,可以对两个数组进行从小到大排序,把小于k的全部找出来放在集合里面,然后根据集合里面数据内容判断是否满足覆盖1-k的情况。

cpp 复制代码
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long int

void solve() 
{
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	set<ll> s1, s2;
	for (int i = 0; i < n; i++)
	{
		if (a[i] <= k)
			s1.insert(a[i]);
	}
	for (int i = 0; i < m; i++) 
	{
		if (b[i] <= k)
			s2.insert(b[i]);
	}
	set<ll> s;
	if (s1.size() < k / 2 || s2.size() < k / 2)
	{
		cout << "NO" << endl;
		return;
	}
	for (auto i : s1)
	{
		s.insert(i);
	}
	for (auto i : s2)
	{
		s.insert(i);
	}
	for (int i = 1; i <= k; i++)
	{
		if (s.find(i) == s.end())
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main() 
{
	ll t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
相关推荐
weixin_4196583122 分钟前
数据结构之栈
数据结构
图先22 分钟前
数据结构第一章
数据结构
itsuifengerxing37 分钟前
python 自定义无符号右移
算法
猎板PCB厚铜专家大族1 小时前
高频 PCB 技术发展趋势与应用解析
人工智能·算法·设计规范
dying_man1 小时前
LeetCode--24.两两交换链表中的结点
算法·leetcode
yours_Gabriel1 小时前
【力扣】2434.使用机器人打印字典序最小的字符串
算法·leetcode·贪心算法
草莓熊Lotso2 小时前
【数据结构初阶】--算法复杂度的深度解析
c语言·开发语言·数据结构·经验分享·笔记·其他·算法
KyollBM2 小时前
【CF】Day75——CF (Div. 2) B (数学 + 贪心) + CF 882 (Div. 2) C (01Trie | 区间最大异或和)
c语言·c++·算法
CV点灯大师2 小时前
C++算法训练营 Day10 栈与队列(1)
c++·redis·算法
GGBondlctrl3 小时前
【leetcode】递归,回溯思想 + 巧妙解法-解决“N皇后”,以及“解数独”题目
算法·leetcode·n皇后·有效的数独·解数独·映射思想·数学思想