#C6222. Largest Sum Submatrix

    ID: 49959 Type: Default 1000ms 256MiB

Largest Sum Submatrix

Largest Sum Submatrix

You are given an \(M \times N\) matrix of integers. Your task is to find the largest sum that can be obtained from any contiguous submatrix of the given matrix. A contiguous submatrix is defined by a block of consecutive rows and consecutive columns.

For example, for the matrix:

[ \begin{bmatrix} 1 & -2 & 1 & 0 \ -1 & 3 & 4 & -5 \ 2 & -1 & 2 & 1 \ -3 & 4 & -2 & 1 \end{bmatrix} ]

the largest sum of any contiguous submatrix is 10.

Input/Output: Your program should read the input from stdin and print the output to stdout.

inputFormat

The input begins with two integers \(M\) and \(N\) separated by space indicating the number of rows and columns of the matrix, respectively. This is followed by \(M\) lines, each containing \(N\) space-separated integers representing the rows of the matrix.

Example:

4 4
1 -2 1 0
-1 3 4 -5
2 -1 2 1
-3 4 -2 1

outputFormat

Output a single integer which is the largest sum of any contiguous submatrix in the given matrix.

Example:

10
## sample
1 1
5
5