#abc358g. G - AtCoder Tour

G - AtCoder Tour

Score : 550550 points

问题陈述

AtCoder Land 由一个 HHWW 列的网格表示。用 (i,j)(i, j) 表示第 ii 行第 jj 列的单元格。

高桥从单元格 (Si,Sj)(S_i, S_j) 开始,重复以下动作 KK 次:

  • 他要么留在当前单元格,要么移动到相邻单元格。在执行这个动作后,如果他在单元格 (i,j)(i, j),他将获得一个乐趣值 Ai,jA_{i, j}

找出他可以获得的最大总乐趣值。

这里,如果 xx+yy=1|x - x'| + |y - y'| = 1,则认为单元格 (x,y)(x', y') 与单元格 (x,y)(x, y) 相邻。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

AtCoder Land is represented by a grid with HH rows and WW columns. Let (i,j)(i, j) denote the cell at the ii-th row and jj-th column.

Takahashi starts at cell (Si,Sj)(S_i, S_j) and repeats the following action KK times:

  • He either stays in the current cell or moves to an adjacent cell. After this action, if he is in cell (i,j)(i, j), he gains a fun value of Ai,jA_{i, j}.

Find the maximum total fun value he can gain.

Here, a cell (x,y)(x', y') is considered adjacent to cell (x,y)(x, y) if and only if xx+yy=1|x - x'| + |y - y'| = 1.

Constraints

  • 1H,W501 \leq H, W \leq 50
  • 1K1091 \leq K \leq 10^9
  • 1SiH1 \leq S_i \leq H
  • 1SjW1 \leq S_j \leq W
  • 1Ai,j1091 \leq A_{i, j} \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

HH WW KK

SiS_i SjS_j

A1,1A_{1, 1} A1,2A_{1, 2} \ldots A1,WA_{1, W}

A2,1A_{2, 1} A2,2A_{2, 2} \ldots A2,WA_{2, W}

\vdots

AH,1A_{H, 1} AH,2A_{H, 2} \ldots AH,WA_{H, W}

Output

Print the answer.

Sample Input 1

2 3 3
1 2
2 1 2
3 4 5

Sample Output 1

14

Takahashi can gain a total fun value of 1414 by acting as follows:

  • Initially, he is at (1,2)(1, 2).
  • He moves to cell (2,2)(2, 2). Then, he gains a fun value of A2,2=4A_{2, 2} = 4.
  • He moves to cell (2,3)(2, 3). Then, he gains a fun value of A2,3=5A_{2, 3} = 5.
  • He stays in cell (2,3)(2, 3). Then, he gains a fun value of A2,3=5A_{2, 3} = 5.

He cannot gain a total fun value greater than 1414, so print 1414.

Sample Input 2

2 2 1000000000
2 1
100 100
100 99

Sample Output 2

100000000000