Enter | Register
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP
PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST
Codeforces Round 1107 (Div. 3)
D. An Alternative Way Finished
time limit per test: 2 seconds
memory limit per test: 256 megabytes → Virtual participation
You are given two arrays a and b, each of length n. You are allowed to perform the following Virtual contest is a way to take part in past
contest, as close as possible to participation
operation on array a any number of times (including zero): on time. It is supported only ICPC mode for
virtual contests. If you've seen these
1. Choose two indices l and r such that 1 ≤ l ≤ r ≤ n ; problems, a virtual contest is not for you -
solve these problems in the archive. If you
2. For each index i from l to r (both inclusive), just want to solve some problem from a
contest, a virtual contest is not for you -
Set ai := ai − 1 if i − l is odd. solve this problem in the archive. Never use
someone else's code, read the tutorials or
Set ai := ai + 1 if i − l is even. communicate with other person during a
virtual contest.
Determine whether you can make the array a equal to the array b by performing the operation
Start virtual contest
any number of times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10
4
) — the number of test cases. → Problem tags
Description of each test case follows.
dp greedy math
No tag edit access
The first line of each test case contains a single integer n (1
5
≤ n ≤ 2 ⋅ 10 ) — the length of
the arrays a and b.
9
→ Contest materials
The second line of each test case contains n integers a1 , a2 , … , an (1 ≤ ai ≤ 10 ) — the
elements of the array a. Announcement (en)
9
The third line of each test case contains n integers b1 , b2 , … , bn (1 ≤ bi ≤ 10 ) — the Tutorial (en)
elements of the array b.
5
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10 .
Output
For each test case, print "YES" if you can make array a equal to array b and "NO" otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will
be recognized as a positive response).
Example
input Copy
7
3
1 2 3
1 2 3
4
1 4 5 2
1 5 4 3
1
9
8
6
6 7 6 7 6 7
7 6 7 6 7 6
9
9 8 7 6 5 4 3 2 1
9 9 8 2 4 4 3 5 3
3
1 1 2
2 1 1
2
1 2
1 1
output Copy
YES
YES
NO
YES
NO
YES
NO
Note
For the first test case, arrays a and b are already equal.
For the second test case, let us choose l = 2 and r = 4 . Now, we update the array a in the
following manner:
For i = 2 , we have i − l = 2 − 2 = 0 , which is even. Hence, set
a2 := a2 + 1 = 4 + 1 = 5 .
For i = 3 , we have i − l = 3 − 2 = 1 , which is odd. Hence, set
a3 := a3 − 1 = 5 − 1 = 4 .
For i = 4 , we have i − l = 4 − 2 = 2 , which is even. Hence, set
a4 := a4 + 1 = 2 + 1 = 3 .
Finally, we have array a = [1, 5, 4, 3] and array b = [1, 5, 4, 3] .
For the third test case, it can be shown that it is impossible to make array a equal to array b.
Codeforces (c) Copyright 2010-2026 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Jul/03/2026 14:56:59UTC+5.5 (h1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions
Supported by