Codeforces Round 1113 (Div. 2)
B
合并以匹配
Merge to Match
Codeforces
1000
原题
← AC →

合并以匹配AI (CI翻译)

You are given two arrays $a$ and $b$ of lengths $n$ and $m$, respectively. All $n + m$ integers in these arrays are distinct.

你有两个数组 $a$ 和 $b$,它们的长度分别为 $n$ 和 $m$。这两个数组中的全部 $n + m$ 个整数两两不同。AI (CI翻译)

You can perform the following operation on $a$ any number of times (possibly, zero):

你可以对 $a$ 执行以下操作任意次(也可以一次都不执行):AI (CI翻译)

  • Choose two elements of $a$ with values $x$ and $y$, where $x \le y$.
  • Delete these two elements from $a$.
  • Insert one integer $z$ into $a$ such that $x \le z \le y$.
  • 选择 $a$ 中值为 $x$ 和 $y$ 的两个元素,其中 $x \le y$。
  • 从 $a$ 中删除这两个元素。
  • 向 $a$ 中插入一个满足 $x \le z \le y$ 的整数 $z$。
AI (CI翻译)

After performing all operations, you may arrange the elements of $a$ in any order.

执行完所有操作后,你可以以任意顺序排列 $a$ 中的元素。AI (CI翻译)

Determine whether it is possible to make $a$ equal to $b$.

判断是否可以使 $a$ 等于 $b$。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来给出各测试用例的描述。AI (CI翻译)

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the lengths of the arrays $a$ and $b$.

每个测试用例的第一行包含两个整数 $n$ 和 $m$($1 \le n, m \le 2 \cdot 10^5$)——数组 $a$ 和 $b$ 的长度。AI (CI翻译)

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).

第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le 10^9$)。AI (CI翻译)

The third line contains $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \le b_i \le 10^9$).

第三行包含 $m$ 个整数 $b_1, b_2, \ldots, b_m$($1 \le b_i \le 10^9$)。AI (CI翻译)

It is guaranteed that all $n + m$ integers in the arrays $a$ and $b$ are distinct.

保证数组 $a$ 和 $b$ 中的全部 $n + m$ 个整数两两不同。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例中 $n$ 的总和不超过 $2 \cdot 10^5$。AI (CI翻译)

It is guaranteed that the sum of $m$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例中 $m$ 的总和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print "YES" if it is possible to make $a$ equal to $b$, and "NO" otherwise.

对于每个测试用例,如果可以使 $a$ 等于 $b$,输出“YES”,否则输出“NO”。AI (CI翻译)

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.

答案可以使用任意大小写形式。例如,字符串“yEs”、“yes”、“Yes”和“YES”都会被识别为肯定回答。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, choose $1$ and $3$, delete them, and insert $2$.

在第一个测试用例中,选择 $1$ 和 $3$,删除它们,然后插入 $2$。AI (CI翻译)

In the second test case, it can be shown that no sequence of operations can make $a$ equal to $b$.

在第二个测试用例中,可以证明不存在任何操作序列能使 $a$ 等于 $b$。AI (CI翻译)

In the third test case, choose $1$ and $5$, delete them, and insert $4$. Then, choose $3$ and $7$, delete them, and insert $6$.

在第三个测试用例中,选择 $1$ 和 $5$,删除它们,然后插入 $4$。接着,选择 $3$ 和 $7$,删除它们,然后插入 $6$。AI (CI翻译)

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

在第六个测试用例中,首先选择 $1$ 和 $10$,删除它们,然后插入 $5$。接下来,选择 $6$ 和 $100$,删除它们,然后插入 $90$。最后,选择 $4$ 和 $5$,删除它们,然后插入 $5$。AI (CI翻译)

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.

在第七个测试用例中,对于数对 $(1,4)$、$(10,20)$ 和 $(30,40)$,分别删除其中的两个元素,并分别插入 $3$、$15$ 和 $35$。AI (CI翻译)

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

在第九个测试用例中,分别删除数对 $(1,3)$、$(8,18)$ 和 $(25,30)$,并插入 $2$、$15$ 和 $28$。然后,删除 $12$ 和 $15$,并插入 $15$。AI (CI翻译)

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$ 和 $2$,删除它们,然后插入 $2$。接着,选择 $2$ 和 $3$,删除它们,然后插入 $3$。最后,选择 $3$ 和 $5$,删除它们,然后插入 $4$。AI (CI翻译)

样例

Input #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
Output #1
YES
NO
YES
NO
NO
YES
YES
NO
YES
YES
YES
InputCopy OutputCopy
题目信息
题号
2248B
时间限制
1.5 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。