Dynamic maximum sum

In this problem, you have to efficiently keep a vector VV with nn integers. There is just one update operation: given any position ii between 0 and n1n - 1, and an integer xx, set V[i]=xV[i] = x. Appart from that, you have to repeatedly report the maximum sum of all the consecutive subsequences of the current vector.

Input

Input consists of several cases. Every case begins with nn, followed by the initial content of VV, followed by nn operations, each one with a pair ii xx. You can assume 1n1051 \le n \le 10^5, 0i<n0 \le i < n, and 1012x1012-10^{12} \le x \le 10^{12}.

Output

For every case, print n+1n+1 numbers: the maximum sum of consecutive elements inside the vector before the first update, and also after every update. Print a line with 10 dashes at the end of each case.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:33:34.901Z

© Jutge.org, 2006–2026.
https://jutge.org