#P4016. 负载平衡问题
负载平衡问题
Description
Company G has warehouses arranged in a ring along a railway transport line. The amount of goods stored in each warehouse is not necessarily the same. What is the minimum total amount of goods that must be moved to make the inventories of the warehouses equal? When moving goods, you may only transfer goods between adjacent warehouses.
Input Format
The first line contains a positive integer , denoting there are warehouses. The second line contains positive integers, denoting the inventory of the warehouses.
Output Format
Output a single non-negative integer on one line, the minimum total amount of goods to move.
5
17 9 14 16 4
11
Hint
, and it is guaranteed that is a multiple of .
Translated by ChatGPT 5
京公网安备 11011102002149号