Maximum Submatrix Sum

시간 제한0.2초메모리 제한1024 MB

요약
N 곱하기 M 행렬이 주어질 때, 빈 부분행렬을 포함한 모든 연속 직사각형 부분행렬의 합 중 최댓값을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

You are given an N×MN \times M matrix AA. Find the maximum sum of any subrectangular submatrix of this matrix.

Here, a subrectangular submatrix is defined as a contiguous submatrix formed by selecting any rectangular section of the given matrix AA, such that the submatrix includes all rows and columns between two specified pairs of indices (r_1,c_1)(r\_1, c\_1) and (r_2,c_2)(r\_2, c\_2), where 1≤r_1≤r_2≤N1 \le r\_1 \le r\_2 \le N and 1≤c_1≤c_2≤M1 \le c\_1 \le c\_2 \le M, plus the case when the submatrix is empty.

입력

The first line of input contains two space-separated integers: NN and MM, denoting the size of the matrix. (1≤N≤M≤100,000;1 \le N \le M \le 100\\,000; 1≤NM≤100,0001 \le NM \le 100\\,000)

The next NN lines of input contain NMNM integers, where each line has MM space-separated integers, denoting the value of the matrix. Here, the jj-th integer of the ii-th line denotes A_ijA\_{ij}. (−10,000≤A_ij≤10,000-10\\,000 \le A\_{ij} \le 10\\,000)

출력

Output the maximum sum of any subrectangular submatrix on a single line.

힌트

(For Sogang students:) Note that this problem is an improvised version that matches the format of a problem in a general programming contest. While in the exam, the original scoring was:

  • 3535 points for Subtask 1.
  • 2525 points for Subtask 2.
  • 3535 points for Subtask 3.
  • 55 points for Subtask 4.

예제1

  1. 예제 1

    입력
    4 5
    1 2 -1 -4 -20
    -8 -3 4 2 1
    3 8 10 1 3
    -4 -1 1 7 -6
    
    예상 출력
    29