#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int H, W, x, h, w; cin >> H >> W; vector> v; vector> a(H, vector(W)); for (int i=0; i> a[i][j]; v.push_back(make_tuple(a[i][j], i, j)); } } sort(v.begin(), v.end()); int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; vector ans(H, vector(W, 0)); for (auto [z, h, w] : v){ for (int i=0; i<4; i++){ int nh = h + dx[i]; int nw = w + dy[i]; if (0 <= nh && nh < H && 0 <= nw && nw < W){ if (a[nh][nw] > a[h][w]) ans[nh][nw] = max(ans[nh][nw], ans[h][w] + 1); } } } int res = 0; for (int i=0; i