Testing Round 10
翻译中…
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?
翻译中…
Input
翻译中…
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*$.
翻译中…
Output
翻译中…
Print the total minimum number of moves.
翻译中…
样例
Input #1
6
1 6 2 5 3 7
Output #1
12
InputCopy
OutputCopy
题目信息
标签
贪心
模拟
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。