CodeQUEEN 2024 予選 (AtCoder Beginner Contest 358)
G
AtCoder Tour
AtCoder
⌀ 1737
原题
翻译中…

Problem Statement

翻译中…

AtCoder Land is represented by a grid with $H$ rows and $W$ columns. Let $(i, j)$ denote the cell at the $i$-th row and $j$-th column.

翻译中…

Takahashi starts at cell $(S_i, S_j)$ and repeats the following action $K$ times:

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

Find the maximum total fun value he can gain.

翻译中…

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

翻译中…

Constraints

翻译中…
  • $1 \leq H, W \leq 50$
  • $1 \leq K \leq 10^9$
  • $1 \leq S_i \leq H$
  • $1 \leq S_j \leq W$
  • $1 \leq A_{i, j} \leq 10^9$
  • All input values are integers.
翻译中…

Input

翻译中…

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

翻译中…

H W K
S_i S_j
A_{1, 1} A_{1, 2} \ldots A_{1, W}
A_{2, 1} A_{2, 2} \ldots A_{2, W}
\vdots
A_{H, 1} A_{H, 2} \ldots A_{H, W}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2 3 3
1 2
2 1 2
3 4 5
Output #1
14
Takahashi can gain a total fun value of $14$ by acting as follows: - Initially, he is at $(1, 2)$. - He moves to cell $(2, 2)$. Then, he gains a fun value of $A_{2, 2} = 4$. - He moves to cell $(2, 3)$. Then, he gains a fun value of $A_{2, 3} = 5$. - He stays in cell $(2, 3)$. Then, he gains a fun value of $A_{2, 3} = 5$. He cannot gain a total fun value greater than $14$, so print $14$.
Input #2
2 2 1000000000
2 1
100 100
100 99
Output #2
100000000000
题目信息
题号
abc358_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。