| University of Science and Technology of China Freshman Programming Contest 2026(2026 Kruskal Cup) |
|---|
| Закончено |
There are $$$n$$$ resonators placed in order along a corridor. The current frequency offset of the $$$i$$$-th resonator is $$$a_i$$$, and its target offset is $$$b_i$$$.
The tuning device can only be activated from one end of the corridor. In one operation, you may choose any nonzero integer $$$x$$$ and perform one of the following operations:
$$$x$$$ may be positive or negative. Regardless of the magnitude of $$$|x|$$$, the modification counts as exactly one operation.
Find the minimum number of operations required to transform sequence $$$a$$$ into sequence $$$b$$$.
The first line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\times10^5$$$, and the sums of $$$\sum|a_i-a_{i-1}|(i \ge 2)$$$ and $$$\sum|b_i-b_{i-1}|(i \ge 2)$$$, taken over all test cases, do not exceed $$$10^4$$$ respectively.
For each test case, output one integer on a separate line, the minimum number of operations.
430 0 0-1 2 030 0 03 1 441 4 2 86 9 7 132-7 10-7 10
2310
For the first test case, one possible sequence of operations is:
For the third test case, adding $$$5$$$ to the entire sequence is sufficient.
| Название |
|---|


