Title: 11054-wine Trading in Gergovia
The owner of each house either buys the wine or sells the wine, and the number of the wines they buy and sell is the same. Liquor-making people need to transport wine to the home of the person who buys the wine, and every bottle of wine transported to the adjoining house costs a unit of money, asking how to make the overall shipping cost the least.
Problem-solving ideas: Both sell and buy, need to be transported. This allows you to transfer the wine he has in his hand, or the wine he wants, from the first home to the neighboring one. If it's just a liquor store, the demand for the other one will be reduced, and if it's all sold or bought, the other needs a number of drinks. So the first home after that can not be considered, because he has given the wine trade to the next door. In the future, the final demand must be 0, because the total number of liquor-buying is fixed.
Code:
#include <stdio.h> #include <stdlib.h>const int N = 100005;long long Wines[n];int main () {int N;while (scanf ( "%d", &n), N) {for (int i = 0; i < n; i++) {scanf ("%lld", &wines[i]);} Long long, Count = Labs (Wines[0]); for (int i = 1; i < n; i++) {wines[i] + = Wines[i-1];count + Labs (Wines[i]);} printf ("%lld\n", count);} return 0;}