Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created January 18, 2014 15:44
Show Gist options
  • Save KT-Yeh/8492141 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8492141 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cmath>
using namespace std;
int a[100001];
int main()
{
int n;
while(scanf("%d",&n)){
if (n==0) break;
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
long long int ans=0;
for(int i=0;i<n-1;i++){
ans += abs(a[i]);
a[i+1] += a[i];
}
printf("%lld\n",ans);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment