#C8142. Maximum Sum Subgrid
Maximum Sum Subgrid
Maximum Sum Subgrid
You are given a grid of integers with N rows and M columns, and an integer K. Your task is to find the K×K subgrid that has the maximum sum of its elements. The answer should be provided as the 1-indexed coordinates of the subgrid: starting row, starting column, ending row, and ending column.
Note: If there are multiple subgrids with the same maximum sum, output the coordinates of the first subgrid found when iterating from the top-left corner.
The subgrid sum is defined by the formula: \[ S = \sum_{i=0}^{K-1} \sum_{j=0}^{K-1} grid[r+i][c+j] \] where \( (r, c) \) represents the starting cell (0-indexed). The output coordinates, however, should be 1-indexed.
inputFormat
The first line of input contains an integer T representing the number of test cases. Each test case begins with a line containing three integers N, M, and K separated by spaces, where N is the number of rows, M is the number of columns, and K is the size of the subgrid.
The following N lines each contain M space-separated integers, representing the rows of the grid.
outputFormat
For each test case, output four space-separated integers representing the 1-indexed coordinates of the maximum sum K×K subgrid in the order: starting row, starting column, ending row, ending column. Each test case's output should be on a separate line.
## sample3
4 5 2
1 2 -1 -4 -20
-8 -3 4 2 1
3 8 10 1 3
-4 -1 1 7 -6
3 3 2
-1 -1 -1
-1 -1 -1
-1 -1 -1
3 3 1
1 2 3
4 5 6
7 8 9
2 2 3 3
1 1 2 2
3 3 3 3
</p>