Under construction

Still being built. Things may change

Phoenix and Dalgu

Time limit1.5sMemory limit1024 MB

Summary
Dalgu blocks one K by K square avoiding the two corners, and the task is to find the largest-weight monotone path from (1,1) to (N,N) under the best such block.
Level

Medium7 of 10

Topics
Dynamic programming, Prefix sum, Matrix
Solved
No attempts yet

Problem

Phoenix and Dalgu play a game on an N×NN \times N grid. Cell (i,j)(i, j) has weight Ai,jA_{i,j}. The game goes as follows.

  • Dalgu picks one K×KK \times K square region and gives all cells in it to Yooni. However, the chosen region must not contain cell (1,1)(1, 1) or cell (N,N)(N, N).
  • Phoenix starts at cell (1,1)(1, 1) and moves until reaching cell (N,N)(N, N). From cell (r,c)(r, c), Phoenix can move to (r+1,c)(r+1, c) or (r,c+1)(r, c+1). Phoenix cannot move outside the grid or onto cells given to Yooni.
  • Phoenix's score is the sum of the weights of the cells Phoenix passes through.

Phoenix wants the score to be as large as possible, and Dalgu chooses the region to make it as small as possible. Assuming both play optimally, find the maximum score Phoenix can obtain.

Input

The first line contains two integers NN and KK, separated by a space. (2≤N≤20002 \le N \le 2000; 1≤K<N1 \le K < N)

Each of the next NN lines contains NN integers Ai,1,Ai,2,⋯ ,Ai,NA_{i,1}, A_{i,2}, \cdots, A_{i,N}, separated by spaces. (0≤Ai,j≤100000 \le A_{i,j} \le 10000)

Output

Print the maximum score Phoenix can obtain.

Examples1

  1. Example 1

    Input
    5 3
    4 8 13 2 5
    0 7 7 3 12
    25 3 11 5 6
    9 12 0 28 3
    1 13 5 8 9
    
    Expected output
    65