Problem10887--ABC358 - G - AtCoder Tour

10887: ABC358 - G - AtCoder Tour

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

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$.

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.

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.

Sample 1 Input

2 3 3
1 2
2 1 2
3 4 5

Sample 1 Output

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$.

Sample 2 Input

2 2 1000000000
2 1
100 100
100 99

Sample 2 Output

100000000000

Source/Category