AtCoder Beginner Contest 182
D
Wandering
AtCoder
⌀ 701
原题
← CE →
翻译中…

Problem Statement

翻译中…

Given is a number sequence $A_1, A_2, A_3, \dots, A_N$, which may contain negative elements. On a number line, there is a robot at coordinate $0$. It will do the following actions in order:

翻译中…
  • Move $A_1$ in the positive direction.
  • Move $A_1$ in the positive direction, and then move $A_2$ in the positive direction.
  • Move $A_1$ in the positive direction, then move $A_2$ in the positive direction, and then move $A_3$ in the positive direction.
翻译中…

$\hspace{140pt} \vdots$

翻译中…
  • Move $A_1$ in the positive direction, then move $A_2$ in the positive direction, then move $A_3$ in the positive direction, $\ldots$, $\dots$, and then move $A_N$ in the positive direction.
翻译中…

Find the greatest coordinate occupied by the robot from the beginning to the end of the process.

翻译中…

Constraints

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

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N

翻译中…

Output

翻译中…

Print the greatest coordinate occupied by the robot from the beginning to the end of the process.

翻译中…

样例

Input #1
3
2 -1 -2
Output #1
5
The robot moves as follows: - Move $2$ in the positive direction, to coordinate $2$. - Move $2$ in the positive direction, to coordinate $4$. Then move $-1$ in the positive direction, to coordinate $3$. - Move $2$ in the positive direction, to coordinate $5$. Then move $-1$ in the positive direction, to coordinate $4$. Then move $-2$ in the positive direction, to coordinate $2$. The greatest coordinate occupied during the process is $5$, so we should print $5$.
Input #2
5
-2 1 3 -1 -1
Output #2
2
Input #3
5
-1000 -1000 -1000 -1000 -1000
Output #3
0
In this case, the initial coordinate $0$ is the greatest coordinate occupied.
题目信息
题号
abc182_d
时间限制
2 s
内存限制
1024 MB

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