A - Adaptation Stories

IME Starters Try-outs 2018

A - Adaptation Stories 

During the military adaptation period, the candidate DH forgot to bring his water bottle to drill. So that he would not run out of water, the military training leaders lent him a water gallon, affectionately called by minalbinha. However it should also be used to resupply the water bottle of the other candidates.

During the training, the military training leaders will bring some amount of water to refill minalbinha and the other candidates will take some amount of water from minalbinha to refill their bottles.

DH, being the responsible for minalbinha, knows the order and the amount of water of every request. He asked your help to determine the minimum amount of water needed to bring on minalbinha so that every request can be satisfied.

Consider that minalbinha can carry any amount of water.

Input

The first line of input contains one integer, nn (0≤n≤1050≤n≤105) — the number of requests.

The next line contains nn integers, vivi (−1000≤vi≤1000−1000≤vi≤1000, vi≠0vi≠0) — the amount of water of ii-th request. If vivi is negative, the water is being taken from minalbinha, otherwise the water is being given to minalbinha.

Output

Print the minimum amount of water that is needed to bring on minalbinha to fulfill all requests.

Examples

Input

7
2 1 -1 -4 3 -5 3

Output

4

Input

3
10 3 -10

Output

0

Input

3
-10 -10 -10

Output

30

水题

 


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int now,m,n,a[100005];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
    {
        now+=a[i];
        m=min(now,m);
    }
    m=-m;
    printf("%d\n",m);



    return 0;
}

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值