#P16214. [ECUSTPC 2025] 午夜季风
[ECUSTPC 2025] 午夜季风
Problem Description
There are pufferfish in front of Maddy. Each pufferfish has a size value . Pufferfish with very different sizes will explode when placed together, so Maddy decides to arrange them in a line. Let the sizes from left to right after arranging be . Then Maddy defines the explosion level of this line of pufferfish as
$$B = \sum \limits_{i < j, |i - j| > 1} |a_i' - a_j'|$$Now the pufferfish change at midnight. Specifically, there are transformations. In each transformation, the size of one pufferfish increases by (when , the pufferfish size decreases by ). After each transformation, Maddy wants you to find an arrangement of the pufferfish in a line that minimizes the explosion level, and you need to output the corresponding explosion level .
Note that each transformation has a lasting effect, meaning the effect of the previous transformation remains and will affect subsequent computations and transformations.
Also note that pufferfish sizes can be negative.
Input Format
The first line contains an integer (), indicating the number of test cases.
For each test case, the first line contains two integers and (), representing the number of pufferfish and the number of transformations.
The next line contains integers (), representing the sizes of the pufferfish. Note that pufferfish sizes can be negative.
Then follow lines, each containing two integers and (), indicating the index of the pufferfish and the change in its size for each transformation.
It is guaranteed that for each test case, , and over all input testdata, and are both at most .
Output Format
For each test case, output one integer per line for each transformation, representing the minimum possible explosion level among all arrangements after that transformation.
1
4 3
1 2 3 4
4 0
2 5
1 -2
3
6
8
Hint
Sample 1 Explanation
After the first transformation, the pufferfish sizes are still . The optimal arrangement is , and the explosion level is $B = |a_1 - a_3| + |a_1 - a_4| + |a_2 - a_4| = |2 - 1| + |2 - 3| + |4 - 3| = 3$。
After the second transformation, the pufferfish sizes are . The optimal arrangement is , and the explosion level is $B = |a_1 - a_3| + |a_1 - a_4| + |a_2 - a_4| = |3 - 1| + |3 - 4| + |7 - 4| = 6$。
After the third transformation, the pufferfish sizes are . The optimal arrangement is , and the explosion level is $B = |a_1 - a_3| + |a_1 - a_4| + |a_2 - a_4| = |3 - (-1)| + |3 - 4| + |7 - 4| = 8$。
Translated by ChatGPT 5