#include #include #include #include #include #include #include #include using namespace std; int main() { int H, W; cin >> H >> W; vector> A(H, vector(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cin >> A[i][j]; } int dx[2] = {0, 1}, dy[2] = {1, 0}; vector>> f(2, vector>(H, vector(W, -1))); queue> q; q.push({0, 0, 0, A[0][0]}); f[0][0][0] = A[0][0]; while (!q.empty()) { auto [id, x, y, d] = q.front(); q.pop(); if (f[id][x][y] > d) continue; for (int i = 0; i < 2; i++) { int nx = x + dx[i], ny = y + dy[i]; if (0 <= nx && nx < H && 0 <= ny && ny < W) { if (d <= A[nx][ny] && id == 0 && (nx != H - 1 || ny != W - 1)) { f[1][nx][ny] = max(f[1][nx][ny], d); q.push({1, nx, ny, d}); } else if (d > A[nx][ny]) { f[id][nx][ny] = max(f[id][nx][ny], A[nx][ny] + d); q.push({id, nx, ny, A[nx][ny] + d}); } } } } if (f[0][H - 1][W - 1] != -1 || f[1][H - 1][W - 1] != -1) cout << "Yes" << endl; else cout << "No" << endl; }