Question link:https://www.spoj.com/problems/GERGOVIA/11
import java.util.Scanner;
public class WineTradingInGergovia {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
int N = scanner.nextInt();
if (N == 0) {
break;
}
long totalCost = 0;
long balance = 0;
for (int i = 0; i < N; i++) {
int wine = scanner.nextInt();
balance += wine;
totalCost += Math.abs(balance);
}
System.out.println(totalCost);
}
scanner.close();
}
}
created
last reply
- 4
replies
- 169
views
- 2
users
- 2
likes
- 3
links