Codeforces Round 670 (Div. 2)
D
Three Sequences
Codeforces
2200
原题
← CE →
翻译中…

You are given a sequence of $n$ integers $a_1, a_2, \ldots, a_n$.

翻译中…

You have to construct two sequences of integers $b$ and $c$ with length $n$ that satisfy:

翻译中…
  • for every $i$ ($1\leq i\leq n$) $b_i+c_i=a_i$
  • $b$ is non-decreasing, which means that for every $1 \lt i\leq n$, $b_i\geq b_{i-1}$ must hold
  • $c$ is non-increasing, which means that for every $1 \lt i\leq n$, $c_i\leq c_{i-1}$ must hold
翻译中…

You have to minimize $\max(b_i,c_i)$. In other words, you have to minimize the maximum number in sequences $b$ and $c$.

翻译中…

Also there will be $q$ changes, the $i$-th change is described by three integers $l,r,x$. You should add $x$ to $a_l,a_{l+1}, \ldots, a_r$.

翻译中…

You have to find the minimum possible value of $\max(b_i,c_i)$ for the initial sequence and for sequence after each change.

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($1\leq n\leq 10^5$).

翻译中…

The secound line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\leq i\leq n$, $-10^9\leq a_i\leq 10^9$).

翻译中…

The third line contains an integer $q$ ($1\leq q\leq 10^5$).

翻译中…

Each of the next $q$ lines contains three integers $l,r,x$ ($1\leq l\leq r\leq n,-10^9\leq x\leq 10^9$), desribing the next change.

翻译中…

Output

翻译中…

Print $q+1$ lines.

翻译中…

On the $i$-th ($1 \leq i \leq q+1$) line, print the answer to the problem for the sequence after $i-1$ changes.

翻译中…

Note

翻译中…

In the first test:

翻译中…
  • The initial sequence $a = (2, -1, 7, 3)$. Two sequences $b=(-3,-3,5,5),c=(5,2,2,-2)$ is a possible choice.
  • After the first change $a = (2, -4, 4, 0)$. Two sequences $b=(-3,-3,5,5),c=(5,-1,-1,-5)$ is a possible choice.
  • After the second change $a = (2, -4, 6, 2)$. Two sequences $b=(-4,-4,6,6),c=(6,0,0,-4)$ is a possible choice.
翻译中…

样例

Input #1
4
2 -1 7 3
2
2 4 -3
3 4 2
Output #1
5
5
6
InputCopy OutputCopy
Input #2
6
-9 -10 -9 -6 -5 4
3
2 6 -9
1 2 -10
4 6 -3
Output #2
3
3
3
1
InputCopy OutputCopy
Input #3
1
0
2
1 1 -1
1 1 -1
Output #3
0
0
-1
InputCopy OutputCopy
题目信息
题号
1406D
时间限制
2 s
内存限制
512 MB
标签
构造
数据结构
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。