Maximum Submatrix Sum
InterviewTime limit0.2sMemory limit1024 MB
Given an N by M integer matrix, find the maximum sum of any contiguous rectangular submatrix, where the empty submatrix counts as 0.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
You are given an matrix . Find the maximum sum of any subrectangular submatrix of this matrix.
Here, a subrectangular submatrix is a contiguous submatrix formed by selecting a rectangular section of the given matrix . It includes all rows and columns between two specified pairs of indices and , where and . The empty submatrix is also allowed.
Input
The first line of input contains two space-separated integers: and , the size of the matrix. ( )
The next lines of input contain integers, where each line has space-separated integers, denoting the values of the matrix. The -th integer of the -th line is . ()
Output
Output the maximum sum of any subrectangular submatrix on a single line.
Hint
(For Sogang students:) This problem is an adapted version that fits the format of a general programming contest. In the exam, the original scoring was:
- Subtask 1: points.
- Subtask 2: points.
- Subtask 3: points.
- Subtask 4: points.