Server Overload

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

요약
n x n 격자에서 서로 겹치지 않는 가로 1x3 구간을 최대 k개 골라 덮인 칸의 합이 최대가 되도록 한다.
난이도

보통10점 중 7점

유형
동적 계획법, 슬라이딩 윈도우, 누적 합
정답자
아직 제출이 없습니다

문제

The IT team of a SY company manages the sever log data. This log data is organized into an n×nn \times n grid, with each cell storing a number indicating the server access count during a specific time period. The server has recently been overloaded and is at risk of going down. To determine the cause of the server overload, the IT team uses a specialized 1×31 \times 3 analysis tool to find the sub-grids of n×nn \times n grid that represent the high access counts. The 1×31 \times 3 analysis tool covers some 1×31 \times 3 sub-grid (of the n×nn \times n grid) of vertical length of 11 and of horizontal length of 33. The tool reports the sum of access counts stored in the cells of the sub-grid that the tool covers. The only limitation is that you can use this analysis tool at most kk times and the 1×31 \times 3 sub-grids covered by the tool should not overlap.

Given an n×nn \times n grid and a positive integer kk, write a program that outputs the maximum of the total sum of access counts stored in cells of the n×nn \times n grid covered by the 1×31 \times 3 analysis tool, such that the tool is used at most kk times and no 1×31 \times 3 sub-grids covered by the tool overlap.

입력

Your program is to read from standard input. The input starts with a line containing two integers, nn and kk (3≤n≤1,0003 ≤ n ≤ 1\\,000, 1≤k≤5,0001 ≤ k ≤ 5\\,000), where nn represents the size of the grid and kk is the maximum number of times that the analysis tool can be used. In the following nn lines, access count values of the n×nn \times n grid are given; the ii-th line contains nn access count values (from the first column to the last column) of the ii-th row of the grid. All these access count values are integers between 11 and 1,000,000,0001\\,000\\,000\\,000.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the maximum of the total sum of access counts in cells covered by the analysis tool such that the tool can be used at most kk times and no 1×31 \times 3 sub-grids covered by the tool overlap.

예제2

  1. 예제 1

    입력
    5 2
    1 2 3 1 2
    3 4 2 5 6
    2 4 2 3 5
    5 4 3 2 5
    6 5 4 3 5
    
    예상 출력
    28
    
  2. 예제 2

    입력
    6 3
    1 2 3 1 2 1
    3 4 2 5 6 2
    2 4 2 3 5 5
    8 8 8 8 8 8
    9 9 9 9 9 1
    1 2 1 2 3 1
    
    예상 출력
    75