#C2670. Minimum Operations to Uniform Matrix
Minimum Operations to Uniform Matrix
Minimum Operations to Uniform Matrix
Given an integer matrix \(A\) of dimensions \(m \times n\), the goal is to determine the minimum number of operations required to make all its elements equal. In one operation, you can increment any element of the matrix by 1.
To make the matrix uniform, every element must eventually equal the maximum element \(M\) of the matrix, where \(M = \max_{1 \le i \le m, 1 \le j \le n} A_{i,j}\). The total number of operations needed is given by:
\( \sum_{i=1}^{m} \sum_{j=1}^{n}(M - A_{i,j}) \)
You are given \(t\) test cases. For each test case, compute the number of operations required to transform the matrix into a uniform matrix.
inputFormat
The first line contains an integer \(t\), the number of test cases.
For each test case, the first line contains two integers \(m\) and \(n\) representing the number of rows and columns respectively. This is followed by \(m\) lines, each containing \(n\) space-separated integers which are the elements of the matrix.
outputFormat
For each test case, output a single integer representing the minimum number of operations required to make the matrix uniform. Each result must be printed on a new line.
## sample2
2 2
1 3
2 4
3 3
1 1 1
1 1 1
1 1 1
6
0
</p>