QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 256 MB 총점: 100 해킹 가능 ✓

#17664. 凯文与数字

통계

Kevin 在黑板上写了一个长度为 $n$ 的整数序列 $a$。

Kevin 可以进行任意次以下操作:

  • 选择黑板上的两个整数 $x, y$,满足 $|x - y| \le 1$,擦除它们,然后写下一个整数 $x + y$。

Kevin 想知道是否可以通过某种操作序列将这些整数转换为长度为 $m$ 的整数序列 $b$。

两个序列 $a$ 和 $b$ 被认为是相同的,当且仅当它们的多重集(multiset)完全相同。换句话说,对于任意数字 $x$,$x$ 在 $a$ 中出现的次数必须等于它在 $b$ 中出现的次数。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是测试用例的描述。

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

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

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

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

输出格式

对于每个测试用例,如果可以将 $a$ 转换为 $b$,则输出 "Yes",否则输出 "No"。

你可以以任何大小写形式输出答案(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 都会被识别为肯定的回答)。

样例

输入样例 1

9
2 1
4 5
9
2 1
3 6
9
4 2
1 2 2 2
3 4
4 2
1 1 3 3
3 5
4 2
1 2 3 4
3 5
5 5
1 2 3 4 5
5 4 3 2 1
4 2
1 1 1 1
1 1
4 4
1 1 1 1
1 1 1 2
1 1
1
1000000000

输出样例 1

Yes
No
Yes
Yes
No
Yes
No
No
No

说明

在第一个测试用例中,你可以擦除 $4, 5$,并写下 $9$。

在第二个测试用例中,你不能擦除 $3, 6$。

在第三个测试用例中,一种可能的方法是:

  • 擦除 $2, 2$,并写下 $4$。此时剩余的数字为 $1, 2, 4$。
  • 擦除 $1, 2$,并写下 $3$。此时剩余的数字为 $3, 4$。

在第四个测试用例中,一种可能的方法是:

  • 擦除 $1, 1$,并写下 $2$。此时剩余的数字为 $2, 3, 3$。
  • 擦除 $2, 3$,并写下 $5$。此时剩余的数字为 $3, 5$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.