#P13822. 「Diligent-OI R2 B」白露为霜
「Diligent-OI R2 B」白露为霜
Description
A sequence is called a polyline if and only if for , the condition is satisfied. Specifically, a sequence of length is also considered a polyline.
Given and two sequences and of length , where both and are polylines, you can perform the following operation on any number of times:
Choose an integer and modify to any value, but you must ensure that after the modification, the sequence remains a polyline.
The question is: Can you make equal to ? Note: You do not need to print the operation steps.
Input Format
Note that this problem requires efficient input and output methods.
The input consists of multiple test cases. The first line contains , the number of test cases.
For each test case:
The first line contains .
The second line contains integers .
The third line contains integers .
Output Format
For each test case, output one line. If it is impossible to make equal to , output No; otherwise, output Yes. Note: You do not need to print the operation steps.
3
1
1
2
4
1 2 3 4
3 2 3 2
2
1 2
2 1
Yes
Yes
No
Hint
Sample #1 Explanation
First test case: .
Second test case: .
Third test case: It can be proven that there is no solution.
Data Range
Let be the sum of across all test cases in a single test point.
For of the data, $1\le T\le10^6,1\le n\le10^6,1\le N\le10^6,1\le a_i\le10^9$.
- Testcase 1: .
- Testcase 2: .
- Testcase 3: .
- Testcase 4: For any , .
- Testcase 5: No additional constraints.
京公网安备 11011102002149号