#abc339c. C - Perfect Bus

C - Perfect Bus

Score: 250250 points

问题描述

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

在某一时刻,公交车上可能有零个或多个乘客,并且从那时起已经停靠了 NN 次。在第 ii 次停车时,乘客人数增加了 AiA_i。这里,AiA_i 可以为负数,意味着乘客人数减少了 Ai-A_i。此外,除了在这些停车点外,没有乘客上下车。

请找出与给定信息相一致的、当前公交车上乘客数目的最小可能值。

以上为通义千问 qwen-max 翻译,仅供参考。

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 NN times since then. At the ii-th stop, the number of passengers increased by AiA_i. Here, AiA_i can be negative, meaning the number of passengers decreased by Ai-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

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 109Ai109-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:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print the answer.

Sample Input 1

4
3 -5 7 -4

Sample Output 1

3

If the initial number of passengers was 22, the current number of passengers would be 2+3+(5)+7+(4)=32 + 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

update @ 2024/3/10 01:31:08