← 返回 amazon 的题目列表Minimize Operations for Even Box Distribution
类型:online_judge
Amazon has several warehouses, each having n piles numbered 1, 2, ..., n, with the ith pile containing boxes[i] boxes. To achieve even distribution, the caretaker can perform the following operation any number of times: choose two distinct piles, i and j (1 ≤ i, j ≤ n) with boxes[i] > 0, remove one box from pile i and place it on pile j, thus incrementing boxes[j] by 1 and decrementing boxes[i] by 1. The caretaker wishes to minimize the difference between the maximum and minimum number of boxes in the piles, denoted as d. The goal is to find the minimum number of operations required to achieve the difference d.
Example
Input
3
[7, 2, 5]