11054-wine Trading in Gergovia

Source: Internet
Author: User


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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.