CF440B.Balancer

普及/提高-

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configuration?

彼得有 kk 根火柴,放置在从左到右排成一行的 nn 个火柴盒中。已知 kk 能被 nn 整除。彼得希望每个盒子中的火柴数量都相同。为此,他每次可以将一根火柴从一个盒子移动到其相邻的盒子(左邻或右邻)。为达到目标状态,他最少需要多少次这样的移动?

输入格式

The first line contains integer n (1 ≤ n ≤ 50000). The second line contains n non-negative numbers that do not exceed 109, the i-th written number is the number of matches in the i-th matchbox. It is guaranteed that the total number of matches is divisible by n.

第一行包含一个整数 nn(1≤n≤500001 \leq n \leq 50000)。第二行包含 nn 个非负整数,每个数都不超过 10910^9;其中第 ii 个数表示第 ii 个火柴盒中的火柴数量。保证火柴总数能被 nn 整除。

输出格式

Print the total minimum number of moves.

输出所需的最少总步数。

输入输出样例

  • 输入#1

    6
    1 6 2 5 3 7

    输出#1

    12

输入解题思路,AI测评打分。不知道怎么写?

首页