#K68957. Maximum Grid Stabilization Hours
Maximum Grid Stabilization Hours
Maximum Grid Stabilization Hours
You are given a grid of integers where each cell represents the moisture level. In one hour, the difference between the highest and lowest moisture level is reduced by 1 until all cells become equal. The maximum number of hours required to stabilize the grid is determined by the difference between the maximum and minimum values in the grid.
Mathematically, if \(A\) is the set of all moisture values in the grid, then the number of hours \(H\) required to stabilize the grid is given by:
[ H = \max(A) - \min(A) ]
Your task is to compute \(H\) for a given grid.
inputFormat
The first line of input contains an integer \(T\) representing 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 in the grid.
- The next \(M\) lines each contain \(N\) space-separated integers representing the moisture levels in the grid.
The input is provided via standard input (stdin).
outputFormat
For each test case, output one line containing a single integer — the maximum number of hours required for the grid to stabilize. The output should be written to standard output (stdout).
## sample1
1 1
5
0
</p>