パナソニックプログラミングコンテスト(AtCoder Beginner Contest 186)
翻译中…
Problem Statement
翻译中…
We have a grid with $H$ horizontal rows and $W$ vertical columns. The square at the $i$-th row from the top and $j$-th column from the left has $A_{i, j}$ blocks stacked on it.
翻译中…
At least how many blocks must be removed to make all squares have the same number of blocks?
翻译中…
Constraints
翻译中…
$1 \leq H,W \leq 100$$0\leq A_{i,j} \leq 100$
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
H W
A_{1,1} A_{1,2} \ldots A_{1,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}
翻译中…
Output
翻译中…
Print the minimum number of blocks that must be removed.
翻译中…
样例
Input #1
2 3
2 2 3
3 2 2
Output #1
2
Removing $1$ block from the top-right square and $1$ from the bottom-left square makes all squares have $2$ blocks.
Input #2
3 3
99 99 99
99 0 99
99 99 99
Output #2
792
Input #3
3 2
4 4
4 4
4 4
Output #3
0
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。