No.2855 Move on Grid
タグ : / 解いたユーザー数 106
作問者 :
sepa38
Problem Statement
There is an $N \times M$ grid.
The cell $(i, j)$ in the $i$-th row from the top and the $j$-th column from the left has an integer $A_{i, j}$ written on it.
You are going to travel from the top-left cell $(1, 1)$ to the bottom-right cell $(N, M)$ by moving up, down, left, or right.
You may perform the following action up to $K$ times.
- Choose integers $i, j$ satisfying $1 \leq i \leq N, 1 \leq j \leq M$, and change the integer written on cell $(i, j)$ to any integer from $1$ to $10^{9}$.
The score is the minimum of the integers written on the cells you passed through during the move, including $(1, 1) と (N, M)$.
Find the maximum possible score.
Constraints
- $2 \leq N, M \leq 300$
- $0 \leq K \leq N \times M$
- $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.
$N$ $M$ $K$
$A_{1,1}$ $A_{1,2}$ ... $A_{1,M}$
$A_{2,1}$ $A_{2,2}$ ... $A_{2,M}$
$\vdots$
$A_{N,1}$ $A_{N,2}$ ... $A_{N,M}$
Output
Print the answer to the problem on one line.
Sample
Sample 1
Input
3 3 2 1 2 4 3 5 7 6 8 9
Output
6
For example, if you change the integer written on cell $(1, 1)$ to $7$ and the integer written on cell $(2, 1)$ to $8$, you can achieve a score of $6$.
Sample 2
Input
5 5 0 1 7 7 7 7 1 7 1 1 1 1 7 1 7 1 1 7 1 7 1 1 1 1 7 1
Output
1
Note that you can move up, down, left, and right.
Sample 3
Input
2 3 6 2 3 3 5 7 8
Output
1000000000
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。