AtCoder Regular Contest 136
C
Circular Addition
AtCoder
⌀ 2137
原题
← BD →
翻译中…

Problem Statement

翻译中…

We have an integer sequence of length $N$: $x=(x_0,x_1,\cdots,x_{N-1})$ (note that its index is $0$-based). Initially, all elements of $x$ are $0$.

翻译中…

You can repeat the following operation any number of times.

翻译中…
  • Choose integers $i,k$ ($0 \leq i \leq N-1$, $1 \leq k \leq N$). Then, for every $j$ such that $i \leq j \leq i+k-1$, increase the value of $x_{j\bmod N}$ by $1$.
翻译中…

You are given an integer sequence of length $N$: $A=(A_0,A_1,\cdots,A_{N-1})$. Find the minimum number of operations needed to make $x$ equal $A$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 200000$
  • $1 \leq A_i \leq 10^9$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_0 A_1 \cdots A_{N-1}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
1 2 1 2
Output #1
2
We should do the following. - Initially, we have $x=(0,0,0,0)$. - Do the operation with $i=1,k=3$, making $x=(0,1,1,1)$. - Do the operation with $i=3,k=3$, making $x=(1,2,1,2)$.
Input #2
5
3 1 4 1 5
Output #2
7
Input #3
1
1000000000
Output #3
1000000000
题目信息
题号
arc136_c
时间限制
2 s
内存限制
1024 MB

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