#C6219. Maximum Hourglass Sum
Maximum Hourglass Sum
Maximum Hourglass Sum
You are given a two-dimensional grid of integers of size M × N. Your task is to find the maximum sum of an hourglass shape within the grid.
An hourglass shape in a 3 × 3 subgrid is defined as:
$$\begin{matrix}a & b & c\\ & d \\e & f & g\end{matrix}$$
The hourglass sum is the sum of the values at these positions. You need to consider all possible hourglasses in the grid and output the maximum sum found.
inputFormat
The input begins with an integer T on the first line, representing the number of test cases.
For each test case:
- The first line contains two space-separated integers M and N representing the dimensions of the grid.
- This is followed by M lines, each containing N space-separated integers representing the grid elements.
All input is read from standard input (stdin).
outputFormat
For each test case, output a single line containing the maximum hourglass sum found in the grid.
The output should be written to standard output (stdout).
## sample2
3 3
1 1 1
0 1 0
1 1 1
4 4
1 2 3 0
0 1 0 0
5 0 0 0
7 8 9 6
7
25
</p>