Problems > Maximum Rectangle Sum

Maximum Rectangle Sum

Difficulty: 2000 6000 ms 128 MB

dp

Print the maximum sum over all non-empty axis-aligned sub-rectangles of an N×M integer grid.

Input: the first line has N and M; the next N lines have the grid rows.

Output: the maximum sub-rectangle sum.

Constraints:

  • 1 ≤ N, M ≤ 500
  • |values| ≤ 100

Sample Tests

Input 1
2 2
1 -2
-3 4
Output 1
4
Input 2
1 3
-1 -2 -3
Output 2
-1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.