走格子 51nod

球最少需要的能量,就是保证能量一直>=0,从头遍历取过程中能量最小值,绝对值为答案。

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 50001
#define INF 0x3f3f3f3f
int main()
{
    LL a[MAXN],n,m=INF,temp=0;
    scanf("%lld",&n);
    for(LL i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        temp+=a[i];
        if(temp<0)
            m = min(m,temp);
    }
    printf("%lld\n",-m);
    return 0;
}

 

posted @ 2017-01-07 11:17  joeylee97  阅读(96)  评论(0编辑  收藏  举报