#P7402. [COCI 2020/2021 #5] Sjeckanje
[COCI 2020/2021 #5] Sjeckanje
Description
You are given an array containing integers. Then there are updates. Each update gives integers , meaning to add to all elements in .
Define the weight of an interval as the maximum value in the interval minus the minimum value in the interval. Now you need to split array into several consecutive intervals. Define the weight of an array that has been split into several intervals as the sum of the weights of all its intervals. For each update, find the maximum possible array weight among all ways to split the array after that update.
Input Format
The first line contains integers , representing the length of the array and the number of updates.
The second line contains integers .
The next lines each contain integers , describing an update.
Output Format
Output lines. On the -th line, output the maximum possible array weight among all splits of array after the -th update.
4 3
1 2 3 4
1 2 1
1 1 2
2 3 1
2
2
0
4 3
2 0 2 1
4 4 1
2 2 3
1 3 2
2
1
3
Hint
Explanation of Sample 1
| Number of updates | Array after this update | One optimal split | Array weight |
|---|---|---|---|
Constraints and Notes
This problem uses bundled testdata.
| Subtask | Points | Constraints and notes |
|---|---|---|
| None |
For of the testdata, , , and .
Additional Notes
The scoring follows the original COCI problem settings, with a full score of .
Translated from COCI2020-2021 CONTEST #5 T5 Sjeckanje.
Translated by ChatGPT 5
京公网安备 11011102002149号