uva 11054

据说这叫扫描法,,,,感觉就是脑洞啊,,,,,反正从最左端开始,如果有酒就往后运,需要酒就运负的,就是相当于后面有酒了就运回来。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int n;
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        ll ans=0,last=0;
        for(int i=0;i<n;i++)
        {
            int a;
            scanf("%d",&a);
            last+=a;
            ans+=abs(last);
            
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

posted on 2017-05-10 21:39  发牌员  阅读(87)  评论(0)    收藏  举报

导航