#P4016. 负载平衡问题

    ID: 2949 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学贪心网络流O2优化最大流费用流网络流 24 题

负载平衡问题

Description

Company G has nn 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 nn warehouses equal? When moving goods, you may only transfer goods between adjacent warehouses.

Input Format

The first line contains a positive integer nn, denoting there are nn warehouses. The second line contains nn positive integers, denoting the inventory of the nn 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

1n100,1ai1001 \leq n \leq 100, 1 \leq a_i \leq 100, and it is guaranteed that ai\sum a_i is a multiple of nn.

Translated by ChatGPT 5