Wine trading in Gergovia UVA - 11054

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/89848541
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;

int main()
{
    int n;
    int a[maxn];
    while(cin>>n && n)
    {
        long long ans = 0;
        for(int i = 0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i = 1;i<=n;i++)
        {
            a[i] +=a[i-1];
        }
        for(int i = 0;i<n;i++)
        {
            ans+= abs(a[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/**
5
5 -4 1 -3 1
6
-1000 -1000 -1000 1000 1000 1000
0
**/

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/89848541