挺簡單的小模擬。
還是要注意思維的方向,要有切入點,不能像無頭蒼蠅一樣東想一下西想一下,而應該分析問題的性質,然后嘗試思維的方向,從不同的方向思考(順序,逆序,排序后,建圖,貪心,dp,搜索等等)
時刻注意數據的范圍,時刻提防爆long long ,不注意往往死的莫名其妙的
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int n;
ll tmp,cur,ans;int main()
{while(~scanf("%d",&n) && n){cur=0;ans=0;for(int i=0;i<n;i++){scanf("%lld",&tmp);cur+=tmp;ans+=abs(cur);}printf("%lld\n",ans);}return 0;
}