P27794 [洛谷] Doraemon Battles the Dragon
普及
题目描述

Problem Description

Doraemon goes out to battle a dragon! He needs to pass through \( n \) levels.

Each level is either a battle with monsters, which deducts a certain amount of health, or a campsite, which increases Doraemon's health by a certain amount.

During the journey, Doraemon's health at any moment must not be less than or equal to 0. Determine the minimum initial health Doraemon needs to complete the mission.

Health is a positive integer.

Input Format

The first line contains a single positive integer \( n \), representing the number of levels.

The second line contains \( n \) integers \( a_i \), representing each level:
- If \( a_i > 0 \), it indicates a campsite that increases health by \( a_i \).
- If \( a_i < 0 \), it indicates a battle that deducts health by \( a_i \).

Output Format

A single line containing a positive integer, representing the minimum initial health Doraemon needs.

Sample Input and Output

Sample Input #1

3
-100 -200 -300

Sample Output #1

601

Sample Input #2

5
-200 -300 1000 -100 -100

Sample Output #2

501

Notes

Sample Explanation

For the second sample: Doraemon starts with 501 health points. After two battles, he has 1 health left, then recovers to 1001, and after the next two battles, he has 801 health, completing the mission.

Data Range and Constraints

For 100% of the data, \( n \leq 100000 \), \( 1 \leq |a_i| \leq 1000 \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 -100 -200 -300
样例输出
601