Cargo Handling (move)

Source: Internet
Author: User
Cargo Handling (move) Title Description

Heaven and earth heartless people sentient beings, one side have difficult p plus support! After the Wenchuan earthquake, the disaster area is the most shortage of relief tents, supporting tents across the country are urgently transported to the disaster area. Suppose that there is a storage point around the Kagawa of N relief tents with circular arrangement, the number of tents per storage point is m1,m2,......,mn, and s=m1+m2+......+mn must be a multiple of n. Any number of tents can be transported to adjacent storage points at any one of the storage points.
Now we need to find a way to carry the fewest tents so that the number of tents in each storage point is the same.
For example: N=5, the number of tents per storage point is 17 9 14 16 4 respectively, we carry out the following handling:
(1) Storage point ① to the storage point ② handling 1 tents;
(2) Storage point ① to the storage point ⑤ handling 4 tents;
(3) Storage point ③ to the storage point ② handling 2 tents;
(4) Storage point ④ 4 tents to the storage point ⑤.
The total number of moving tents is 1+4+2+4=11 and can prove to be the best handling method.

Input

The 1th line is a positive integer n (n≤10000), which indicates that there are n storage points;
Row 2nd n integers (integer range) representing the number of tents in n storage points.

Output

An integer representing the minimum number of tents to be transported.

Sample input
517 9 14) 16 4
Sample output
11

Analysis: Petition Naked questions (you dare say you will not, ( ̄ˇ ̄));

Cargo Handling (move)

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.