



The first line of input contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first line of each test case contains two space-separated integers ‘N’ and ‘M’ representing the number of rows and columns respectively. size of the matrix ‘MAT’.
The next ‘N’ lines of each test case contain ‘M’ single space-separated integers denoting the values of ‘MAT’.
For each test case, print the maximum sum over all submatrices in ‘MAT’.
Print the output of each test case in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 100
1 <= ‘N’, ‘M’<= 100
-100000 <= ‘MAT[i][j]’ <=100000
Where 'MAT[i][j]' represents the value at cell(i, j).
Time limit: 1 sec
The brute force approach is we check for every possible submatrix in the given ‘MAT’.
Here is the algorithm :
As we know, we have to find the maximum sum submatrix. So, the idea is; first, we fix the left and right columns of the ‘MAT’. Then try to find the sum of elements of the submatrix from the left column to the right column for each row and store these values in a ‘MAX_SUM_VALUES’ array/list. After this, we apply Kadane’s algorithm on this array/list ‘MAX_SUM_VALUES’.
Here is the algorithm :