51Nod 1344 走格子 | 贪心

Input示例
5
1
-2
-1
3
4
Output示例
2

贪心

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,n) for(int i = a; i < n; i++)
#define repe(i,a,n) for(int i = a; i <= n; i++)
#define per(i,n,a) for(int i = n; i >= a; i--)
#define clc(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f3f
int main()
{
    
    LL n;
    while(~scanf("%lld",&n)){
        LL m=0,ans=INF,x;
        for(LL i=0;i<n;i++){
            scanf("%lld",&x);
            m+=x;
            ans=min(ans,m);
        }
        if(ans<0)
            printf("%lld
",-ans);
        else
            puts("0");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/kimsimple/p/7463303.html