103392: [Atcoder]ABC339 C - Perfect Bus

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:10 Solved:0

Description

Score: $250$ points

Problem Statement

A bus is in operation. The number of passengers on the bus is always a non-negative integer.

At some point in time, the bus had zero or more passengers, and it has stopped $N$ times since then. At the $i$-th stop, the number of passengers increased by $A_i$. Here, $A_i$ can be negative, meaning the number of passengers decreased by $-A_i$. Also, no passengers got on or off the bus other than at the stops.

Find the minimum possible current number of passengers on the bus that is consistent with the given information.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $-10^9 \leq A_i \leq 10^9$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Print the answer.


Sample Input 1

4
3 -5 7 -4

Sample Output 1

3

If the initial number of passengers was $2$, the current number of passengers would be $2 + 3 + (-5) + 7 + (-4) = 3$, and the number of passengers on the bus would have always been a non-negative integer.


Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Sample Input 3

4
-1 1000000000 1000000000 1000000000

Sample Output 3

3000000000

Input

Output

分数:250分

问题描述

一辆公交车正在运营。公交车上的乘客人数始终为非负整数。

在某个时间点,公交车上有0个或更多的乘客,从那时起,它已经停了$N$次。在第$i$次停车时,乘客人数增加了$A_i$。这里,$A_i$可以为负数,表示乘客人数减少了$-A_i$。此外,除了在停车站外,没有乘客上下车。

根据给定信息,找出公交车上乘客人数的最小可能当前值。

限制条件

  • $1 \leq N \leq 2 \times 10^5$
  • $-10^9 \leq A_i \leq 10^9$
  • 所有输入值都是整数。

输入

输入从标准输入以以下格式给出:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

输出

打印答案。


样例输入1

4
3 -5 7 -4

样例输出1

3

如果初始乘客人数为$2$,则当前乘客人数为$2 + 3 + (-5) + 7 + (-4) = 3$,且公交车上的乘客人数始终保持为非负整数。


样例输入2

5
0 0 0 0 0

样例输出2

0

样例输入3

4
-1 1000000000 1000000000 1000000000

样例输出3

3000000000

加入题单

算法标签: