#K39562. Maximum Sum Submatrix

    ID: 26448 Type: Default 1000ms 256MiB

Maximum Sum Submatrix

Maximum Sum Submatrix

You are given a square matrix of size \(n \times n\) containing non-negative integers and an integer \(k\) representing the submatrix dimension. Your task is to find a \(k \times k\) submatrix whose sum of elements is maximized. In case of multiple submatrices with the same maximum sum, output the indices of the top-left element of any one of them.

For a submatrix with its top-left corner at \((i, j)\), its sum \(S\) is computed as:

\( S = \sum_{p=i}^{i+k-1} \sum_{q=j}^{j+k-1} matrix[p][q] \)

All indices are 1-based.

inputFormat

The input is read from standard input and follows this format: The first line contains two integers (n) and (k) separated by a space, where (n) is the size of the matrix and (k) is the submatrix dimension. The next (n) lines each contain (n) space-separated non-negative integers representing the rows of the matrix.

outputFormat

Print two integers separated by a space representing the 1-based row and column indices of the top-left corner of the (k \times k) submatrix with the maximum sum.## sample

4 2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3 3