luogu#P16331. After All ~綴る想い~
After All ~綴る想い~
Problem Description
You are given a cycle of length . Initially, each position has value , and the positions are numbered from to . You are also given two sequences and , both of length . You may perform the following operation any number of times:
- Choose a point , and add or subtract to the consecutive segment of length starting from position and going forward along the cycle.
Determine whether there exists a sequence of operations such that the value at every position on the cycle is exactly equal to . If so, construct one. For each position, output the number of times you add minus the number of times you subtract .
It is guaranteed that .
If for some test case you can only determine whether a solution exists but cannot construct one, you may still obtain partial score for that test case. See Scoring for details.
Input Format
The first line contains a positive integer , the number of test cases. For each test case:
-
The first line contains a positive integer , the length of the cycle.
-
The second line contains integers , the target values.
-
The third line contains positive integers .
Output Format
For each test case:
-
Output
YESorNOon the first line, indicating your verdict. -
If a solution exists, output integers on the second line, representing your construction. You must ensure that every integer lies between and .
7
5
0 2 2 6 6
1 2 2 2 2
5
-6 -8 -6 21 -6
1 4 2 4 4
5
-2 10 16 0 0
6 6 1 2 2
5
22 14 -2 14 14
4 4 4 8 1
5
2 6 2 2 2
2 1 1 2 1
5
2 3 7 8 8
2 1 2 1 2
5
-5 1 4 -2 -2
1 4 1 1 1
YES
-2 0 2 2 -1
NO
YES
0 2 2 -2 1
YES
0 -2 -2 1 14
YES
0 4 0 2 -2
YES
0 1 3 2 0
YES
-2 1 1 -2 -1
Hint
Constraints
For all test cases, , , .
| Subtask | Special Property | Score | |
|---|---|---|---|
| A | |||
| B | |||
| C | |||
| D | |||
| None |
-
Special Property A: It is guaranteed that , and if a solution exists, then there is always one where the number of additions or subtractions for every does not exceed .
-
Special Property B: It is guaranteed that there exists a nonnegative integer such that .
-
Special Property C: It is guaranteed that all are equal.
-
Special Property D: It is guaranteed that .
Scoring
-
If you correctly determine the existence of a solution for all test cases, you can obtain of the score for that test point. Note that if you can only determine existence, then for the test cases where a solution exists, you should still output a second line consisting of integers within the required range.
-
If you correctly determine the existence of a solution for all test cases, and for every test case with a solution you also construct a valid one, you can obtain of the score for that test point.