这道题用到了
等价转换的思想
所有要运到a1的酒, 都要经过a2, 所以不如把a2的值改成a1+a2,然后依次以此类推。
#include<cstdio>
#include<cmath>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;int main()
{int n;while(~scanf("%d", &n) && n){long long ans = 0, last = 0, x;REP(i, 0, n){scanf("%lld", &x);ans += abs(last);last += x;}printf("%lld\n", ans);}return 0;
}