#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, k; cin >> h >> w >> k; if(k > h + w){ cout << 1'000'000'000 << '\n'; return 0; } vector A(h, vector(w)); cin >> A; k = min(k, h + w); int ok = 0, ng = 1'000'000'005; while(ok + 1 < ng){ int mid = (ok + ng) / 2; vector dp(h, vector(w, 1 << 30)); dp[0][0] = A[0][0] < mid; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ if(y + 1 < h) dp[y + 1][x] = min(dp[y + 1][x], dp[y][x] + (A[y + 1][x] < mid)); if(x + 1 < w) dp[y][x + 1] = min(dp[y][x + 1], dp[y][x] + (A[y][x + 1] < mid)); } } (dp[h - 1][w - 1] <= k ? ok : ng) = mid; } cout << ok << '\n'; }