CF2248B.Merge to Match
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b of lengths n and m, respectively. All n+m integers in these arrays are distinct.
You can perform the following operation on a any number of times (possibly, zero):
- Choose two elements of a with values x and y, where x≤y.
- Delete these two elements from a.
- Insert one integer z into a such that x≤z≤y.
After performing all operations, you may arrange the elements of a in any order.
Determine whether it is possible to make a equal to b.
你有两个长度分别为 n 和 m 的数组 a 和 b。这两个数组中的全部 n+m 个整数互不相同。
你可以对数组 a 执行以下操作任意次(包括零次):
- 选择 a 中两个元素,其值分别为 x 和 y,且满足 x≤y;
- 将这两个元素从 a 中删除;
- 向 a 中插入一个整数 z,使得 x≤z≤y。
在执行完所有操作后,你可以将 a 中的元素以任意顺序排列。
判断是否可能使 a 变为与 b 相等。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n,m≤2⋅105) — the lengths of the arrays a and b.
The second line contains n integers a1,a2,…,an (1≤ai≤109).
The third line contains m integers b1,b2,…,bm (1≤bi≤109).
It is guaranteed that all n+m integers in the arrays a and b are distinct.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
It is guaranteed that the sum of m over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m≤2⋅105)—— 分别表示数组 a 和 b 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
第三行包含 m 个整数 b1,b2,…,bm(1≤bi≤109)。
保证数组 a 和 b 中全部 n+m 个整数互不相同。
保证所有测试用例中 n 的总和不超过 2⋅105。
保证所有测试用例中 m 的总和不超过 2⋅105。
输出格式
For each test case, print "YES" if it is possible to make a equal to b, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个测试用例,如果可以使 a 等于 b,则输出 "YES";否则输出 "NO"。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。
输入输出样例
输入#1
11 2 1 1 3 2 3 2 1 3 5 2 4 4 2 1 3 5 7 4 6 4 2 2 5 8 11 1 10 4 2 1 4 7 9 3 10 5 2 10 1 100 6 4 90 5 6 3 1 4 10 20 30 40 3 15 35 4 2 1 2 3 100 4 5 7 3 1 8 3 30 18 12 25 2 15 28 4 1 1 2 3 5 4 4 2 1 3 5 6 2 4
输出#1
YES NO YES NO NO YES YES NO YES YES YES
说明/提示
In the first test case, choose 1 and 3, delete them, and insert 2.
In the second test case, it can be shown that no sequence of operations can make a equal to b.
In the third test case, choose 1 and 5, delete them, and insert 4. Then, choose 3 and 7, delete them, and insert 6.
In the sixth test case, first choose 1 and 10, delete them, and insert 5. Next, choose 6 and 100, delete them, and insert 90. Finally, choose 4 and 5, delete them, and insert 5.
In the seventh test case, for the pairs (1,4), (10,20), and (30,40), delete both elements and insert 3, 15, and 35, respectively.
In the ninth test case, delete the pairs (1,3), (8,18), and (25,30) and insert 2, 15, and 28, respectively. Then, delete 12 and 15 and insert 15.
In the tenth test case, first choose 1 and 2, delete them, and insert 2. Then, choose 2 and 3, delete them, and insert 3. Finally, choose 3 and 5, delete them, and insert 4.
在第一个测试用例中,选择 1 和 3,删除它们,并插入 2。
在第二个测试用例中,可以证明:不存在任何操作序列能使 a 等于 b。
在第三个测试用例中,选择 1 和 5,删除它们,并插入 4;然后选择 3 和 7,删除它们,并插入 6。
在第六个测试用例中,首先选择 1 和 10,删除它们,并插入 5;接着选择 6 和 100,删除它们,并插入 90;最后选择 4 和 5,删除它们,并插入 5。
在第七个测试用例中,对数对 (1,4)、(10,20) 和 (30,40),分别删除两个元素,并插入 3、15 和 35。
在第九个测试用例中,删除数对 (1,3)、(8,18) 和 (25,30),并分别插入 2、15 和 28;然后删除 12 和 15,并插入 15。
在第十个测试用例中,首先选择 1 和 2,删除它们,并插入 2;然后选择 2 和 3,删除它们,并插入 3;最后选择 3 和 5,删除它们,并插入 4。
输入解题思路,AI测评打分。不知道怎么写?