#P6185. [NOI Online #1 提高组] 序列
[NOI Online #1 提高组] 序列
Problem Description
Little D has an integer sequence of length . She wants to transform it into the sequence through several operations.
Little D has types of operations to choose from. The -th operation can be described by a triple :
- If , then she can either increase both and by , or decrease both by .
- If , then she can either decrease by and increase by , or increase by and decrease by . Therefore, when , this operation is equivalent to doing nothing.
Little D can perform the operations in any order, and each operation can be used an unlimited number of times. Now you are given the sequences and all operations. Please determine whether there exists a plan to transform into . It is guaranteed that both sequences have length . If such a plan exists, output YES; otherwise, output NO.
Input Format
This input contains multiple test cases.
The first line contains a positive integer , the number of test cases. For each test case:
- The first line contains two integers , representing the sequence length and the number of operation types.
- The second line contains integers representing .
- The third line contains integers representing .
- The next lines each contain three integers . Line describes operation .
Note: The same triple may appear multiple times in the input.
Output Format
For each test case, output one line containing a string YES or NO, indicating the answer.
3
1 1
1
3
1 1 1
2 3
1 2
4 5
1 1 2
2 1 2
1 1 2
3 3
1 2 3
5 5 4
1 1 2
1 1 3
2 2 3
YES
YES
YES
Hint
Explanation for Sample 1
For the first test case: use operation once.
For the second test case: use operation three times.
For the third test case: use operation three times to increase both and by , then use operation once to increase both and by .
Constraints and Notes
For test points : , , , , .
For test points : , , , , .
For test points : , , .
For test points : .
For test point : .
For test point : .
For all test points: , , , , .
Translated by ChatGPT 5