23/01/2025, 11:01 Problem - 2061D - Codeforces
Enter | Register
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN
PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST
IAEPC Preliminary Contest
D. Kevin and Numbers (Codeforces Round 999, Div. 1 +
Div. 2)
time limit per test: 2 seconds
Finished
memory limit per test: 256 megabytes
Kevin wrote an integer sequence a of length n on the blackboard. → Virtual participation
Kevin can perform the following operation any number of times: Virtual contest is a way to take part in past
contest, as close as possible to participation
on time. It is supported only ICPC mode for
Select two integers x, y on the blackboard such that |x − y| ≤ 1 , erase them, and then virtual contests. If you've seen these
write down an integer x + y instead. problems, a virtual contest is not for you -
solve these problems in the archive. If you
just want to solve some problem from a
Kevin wants to know if it is possible to transform these integers into an integer sequence b of contest, a virtual contest is not for you -
length m through some sequence of operations. solve this problem in the archive. Never use
someone else's code, read the tutorials or
communicate with other person during a
Two sequences a and b are considered the same if and only if their multisets are identical. In virtual contest.
other words, for any number x , the number of times it appears in a must be equal to the number
Start virtual contest
of times it appears in b.
Input
Each test contains multiple test cases. The first line contains the number of test cases t ( → Problem tags
4
1 ≤ t ≤ 10 ). The description of the test cases follows.
data structures implementation
The first line of each test case contains two integers n and m (1 ≤ m ≤ n ≤ 2 ⋅ 10
5
) — the sortings
length of a and the length of b. No tag edit access
9
The second line contains n integers a1 , a2 , … , an (1 ≤ ai ≤ 10 ).
→ Contest materials
The third line contains m integers b1 , b2 , … , bm (1 ≤ bi ≤ 10
9
).
Announcement (en)
5
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10 .
Tutorial (en)
Output
For each test case, output "Yes" if it is possible to transform a into 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.
Example
input Copy
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
[Link] 1/2
23/01/2025, 11:01 Problem - 2061D - Codeforces
output Copy
Yes
No
Yes
Yes
No
Yes
No
No
No
Note
In the first test case, you can erase 4, 5 , and write down 9.
In the second test case, you can't erase 3, 6 .
In the third test case, one possible way could be:
Erase 2, 2 , and write down 4. The remaining numbers are 1, 2, 4 now.
Erase 1, 2 , and write down 3. The remaining numbers are 3, 4 now.
In the fourth test case, one possible way could be:
Erase 1, 1 , and write down 2. The remaining numbers are 2, 3, 3 now.
Erase 2, 3 , and write down 5. The remaining numbers are 3, 5 now.
Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Jan/22/2025 [Link]UTC-3 (i2).
Desktop version, switch to mobile version.
Privacy Policy
Supported by
[Link] 2/2