QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#17664. Kevin and Numbers

統計

Kevin は黒板に長さ $n$ の整数列 $a$ を書いた。 Kevin は以下の操作を何度でも行うことができる:

  • 黒板上の2つの整数 $x, y$ を選び、$|x - y| \le 1$ であればそれらを消去し、代わりに $x + y$ という整数を書き込む。

Kevin は、一連の操作を通じてこれらの整数を長さ $m$ の整数列 $b$ に変換できるかどうかを知りたいと考えている。 2つの数列 $a$ と $b$ は、それらの多重集合が同一である場合にのみ同じものとみなされる。言い換えれば、任意の数 $x$ について、$a$ に含まれる $x$ の個数は、$b$ に含まれる $x$ の個数と等しくなければならない。

入力

各テストケースには複数のテストケースが含まれる。最初の行にはテストケースの数 $t$ ($1 \le t \le 10^4$) が含まれる。 続いて各テストケースの説明が続く。

各テストケースの最初の行には、2つの整数 $n$ と $m$ ($1 \le m \le n \le 2 \cdot 10^5$) が含まれる。これらは $a$ の長さと $b$ の長さを表す。 2行目には $n$ 個の整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) が含まれる。 3行目には $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を書き込むことができる。 2番目のテストケースでは、3と6を消去することはできない。 3番目のテストケースでは、考えられる手順の一つは以下の通りである:

  • 2と2を消去し、4を書き込む。残りの数は1, 2, 4となる。
  • 1と2を消去し、3を書き込む。残りの数は3, 4となる。

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.