loj#P3467. 「COCI 2021.2」Sjeckanje
「COCI 2021.2」Sjeckanje
Description
Paula likes to prepare stir fry. In order to make it as yummy as possible, she needs to chop a sequence of integers into segments of the maximum total value.
The of a segment is the difference of its maximum and minimum. The value of a chopped sequence is the sum of the values of the segments.
For example if we chop the sequence into segments and , the total value is .
There will be updates of the form “add to the elements on indices ”. After each update, answer the query “What is the maximum possible value of the chopped sequence?”.
Input
The first line contains integers and , the length of the sequence and the number of updates.
The second line contains integers , the sequence Paula needs to chop.
Each of the following lines contains integers , and , describing an update.
Output
Output lines, the maximum possible value of the sequence after each 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
Scoring
Subtask | Constraints | Points |
---|---|---|
No additional constraints. |