#include #include #include #include using namespace std; long long nInhabs; long long dist, amount, cost; int main() { ifstream in("gergovia.in"); in >> nInhabs; int bottles[100000]; while(nInhabs != 0) { for(long long i=0; i> bottles[i]; } cout << "Testcase" << endl; cost = 0; for(long long i=0; i 0) { for (long long k=i+1; k 0) { dist = k-i; amount = bottles[k] * (-1); bottles[i] += bottles[k]; bottles[k] = 0; cost += dist*amount; cout << "1d: " << dist << " a: " << amount << " :cc " << dist*amount << " :c " << cost << endl; } else if (bottles[i] + bottles[k] < 0){ dist = k-i; amount = bottles[i]; bottles[k] += bottles[i]; bottles[i] = 0; cost += dist*amount; cout << "2d: " << dist << " a: " << amount << " :cc " << dist*amount << " :c " << cost << endl; break; } else { dist = k-i; amount = bottles[i]; bottles[k]=bottles[i]=0; cost += dist*amount; cout << "3d: " << dist << " a: " << amount << " :cc " << dist*amount << " :c " << cost << endl; break; } } } } if (bottles[i] < 0) { for (long long k=i+1; k 0) { if (bottles[i] + bottles[k] > 0) { dist = k-i; amount = bottles[i]*(-1); bottles[k] += bottles[i]; bottles[i] = 0; cost += dist*amount; cout << "4d: " << dist << " a: " << amount << " :cc " << dist*amount << " :c " << cost << endl; break; } else if (bottles[i] + bottles[k] < 0){ dist = k-i; amount = bottles[k]; bottles[i] += bottles[k]; bottles[k] = 0; cost += dist*amount; cout << "5d: " << dist << " a: " << amount << " :cc " << dist*amount << " :c " << cost << endl; } else { dist = k-i; amount = bottles[k]; bottles[k]=bottles[i]=0; cost += dist*amount; cout << "6d: " << dist << " a: " << amount << " :cc " << dist*amount << " :c " << cost << endl; break; } } } } } in >> nInhabs; }; return 0; }