#P17445. 长廊调律 / Corridor Tuning
长廊调律 / Corridor Tuning
Problem Description
Along a corridor, resonators are placed in order. The current frequency offset of the -th resonator is , and the target offset is .
The tuning device can only be activated from one end of the corridor. In one operation, you may choose any non-zero integer , and perform one of the following two actions:
- Choose a (), and add to every number in the prefix .
- Choose a (), and add to every number in the suffix .
can be positive or negative. No matter how large is, this modification counts as exactly one operation.
Find the minimum number of operations needed to transform sequence into sequence .
Input Format
The first line contains an integer (), the number of test cases.
For each test case:
- The first line contains an integer ().
- The second line contains integers ().
- The third line contains integers ().
It is guaranteed that the sum of over all test cases does not exceed . Also, over all test cases, the sum of and the sum of are each no more than .
Output Format
For each test case, output one line with one integer, the minimum number of operations.
4
3
0 0 0
-1 2 0
3
0 0 0
3 1 4
4
1 4 2 8
6 9 7 13
2
-7 10
-7 10
2
3
1
0
Hint
For the first test case, you can do:
- Add to the prefix of length , obtaining .
- Add to the prefix of length , obtaining .
For the third test case, adding to the entire sequence is enough.
Translated by ChatGPT 5