302287: CF440B. Balancer
Memory Limit:256 MB
Time Limit:0 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Balancer
题意翻译
题目描述 --- 佩蒂娅有 $k$ 根火柴,她要把这些火柴放在 $n$ 个火柴盒里。佩蒂娅希望所有盒子里的火柴数量相同,也就是每个火柴盒里面要放 $\frac kn$ 根火柴。她可以一步把 $1$ 根火柴从这个盒子里移到相邻的盒子里。问他需要多少次操作才能使得每个盒子都有 $\frac kn$ 根火柴。 输入格式 --- 共两行,第一行只有一个整数 $n$,第二行包含 $n$ 个正整数,分别表示一开始每个火柴盒里面包含的火柴数。 输出格式 --- 只有一个整数,表示至少要操作的次数。题目描述
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?输入输出格式
输入格式
The first line contains integer $ n $ ( $ 1<=n<=50000 $ ). The second line contains $ n $ non-negative numbers that do not exceed $ 10^{9} $ , 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 $ .
输出格式
Print the total minimum number of moves.
输入输出样例
输入样例 #1
6
1 6 2 5 3 7
输出样例 #1
12