406840: GYM102569 E Fluctuations of Mana

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

Description

E. Fluctuations of Manatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A mage is going to visit $$$n$$$ magical sources in fixed order. It is known that after visiting the $$$i$$$-th source the mana is changed by $$$a_i$$$ (this number can be positive, negative or zero). If the mage's mana becomes negative, he dies. What minimal amount of mana should the mage have in the beginning of his journey to successfully visit all $$$n$$$ sources and stay alive?

Input

The first line contains an integer $$$n$$$ ($$$1 \le n \le 500000$$$) — the number of magical sources.

The second line contains $$$n$$$ integers $$$a_i$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the mana change after visiting the $$$i$$$-th source.

Output

Output one integer — the minimal amount of mana the mage should have to successfully complete his journey.

ExampleInput
6
3 -4 2 -3 -2 7
Output
4

加入题单

上一题 下一题 算法标签: