A thinking problem, the main method used is the idea transformation.
First, consider the first villages, the first of his own will with | a [1] | labor
- a [1]> 0 then 2 villages must take a [1] labor to transport, which is required a [1] + a [2] labor
- a [1] <0 then 2 villages have already -a [1] bottle, you can not buy, that is, a [2] - (- a [1]) = a [1] + a [2 ]
In summary, we have to record the first few villages in the village to bring wine by scanning method, accumulated labor just fine
#include <bits / STDC ++ H.> the using namespace STD; int n-; int main () { the while (~ Scanf ( " % D " , & n-) && n-) { Long Long A, ANS = 0 , Last = 0 ; / / not open LL see ancestors for ( int I = . 1 ; I <= n-; I ++ ) { Scanf ( " % LLD " , & A ); ANS + = ABS (Last); // absolute value because the labor-positive last + a =; // add this time of labor } printf("%lld\n",ans); } }