#include using ll = std::int64_t; using T = std::tuple; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int N, M, K; std::cin >> N >> M >> K; std::vector A(N, std::vector(M)); for(int i=0;i> A[i][j]; } } std::vector dist(N, std::vector(M)); std::deque deque; int ok = 1, ng = 1'000'000'001; while(ng - ok >= 2){ int m = (ok + ng) / 2; for(int i=0;i>{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}){ int ni = i + di; int nj = j + dj; if(ni < 0 || N <= ni || nj < 0 || M <= nj){ continue; } int c = A[ni][nj] < m; if(dist[ni][nj] == -1 || dist[ni][nj] > d + c){ dist[ni][nj] = d + c; if(c == 0){ deque.emplace_front(ni, nj, dist[ni][nj]); }else{ deque.emplace_back(ni, nj, dist[ni][nj]); } } } } if(dist[N - 1][M - 1] <= K){ ok = m; }else{ ng = m; } } std::cout << ok << std::endl; }