传统题 1000ms 256MiB

D - Wandering

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

D - Wandering

Score : $400$ points

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:

NN

$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.


3
2 -1 -2
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$.


5
-2 1 3 -1 -1
2

5
-1000 -1000 -1000 -1000 -1000
0

In this case, the initial coordinate $0$ is the greatest coordinate occupied.

2024寒假入门组刷题营(十)

未参加
状态
已结束
规则
ACM/ICPC
题目
8
开始于
2024-2-7 13:30
结束于
2024-2-7 15:30
持续时间
2 小时
主持人
参赛人数
10