101861: [AtCoder]ABC186 B - Blocks on Grid

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

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.


Sample Input 1

2 3
2 2 3
3 2 2

Sample Output 1

2

Removing $1$ block from the top-right square and $1$ from the bottom-left square makes all squares have $2$ blocks.


Sample Input 2

3 3
99 99 99
99 0 99
99 99 99

Sample Output 2

792

Sample Input 3

3 2
4 4
4 4
4 4

Sample Output 3

0

Input

题意翻译

### 题目描述 给出一个 $h$ 行 $w$ 列的方阵,记方阵中左起第 $i$ 行,右起第 $j$ 列的位置上的数为 $a_{i,j}$。请找出方阵中所有元素的最小值,并将方阵中的每个元素的值都减去这个最小值。请输出修改后的方阵中的所有元素的和。 ### 输入格式 输入共 $(h+1)$ 行。第一行为两个正整数 $h$ 和 $w$,接下来的 $h$ 行中每行输入 $w$ 个自然数,即方阵 $a$ 中的所有元素。 ### 输出格式 输出一行一个自然数,即修改后的方阵中所有元素的和。 ### 说明/提示 **数据规模与约定** 对于全部测试点,数据保证: - $1 \le h,w \le 100$; - $0 \le a_{i,j} \le 100$; - 输入的所有数全部为整数。

加入题单

算法标签: