#include #include using namespace std; //#define DISABLE_PRINT #if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT) #define P(...) fprintf(stderr, __VA_ARGS__) #define P2(fmt) fprintf(stderr, fmt) #define LP fprintf(stderr, "L: %d\n", __LINE__) #else #define P(...) ((void)0) #define P2(fmt) ((void)0) #define LP ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define ALL(x) x.begin(),x.end() using ll = long long; using ull = unsigned long long; int main(int, const char**) { int H, W; cin >> H >> W; vector> g(H, vector(W)); rep(i, H) rep(j, W) cin >>g[i][j]; vector> v0(H, vector(W)); v0[0][0] = g[0][0]; { rep(i, H) rep(j, W) { auto p = v0[i][j]; if(p > 0) { if(i < H - 1) { if(p > g[i + 1][j]) { v0[i + 1][j] = p + g[i + 1][j]; } else { v0[i + 1][j] = -p; } } if(j < W - 1) { if(p > g[i][j + 1]) { v0[i][j + 1] = max(v0[i][j + 1], p + g[i][j + 1]); } else { if(v0[i][j + 1] > 0) continue; v0[i][j + 1] = min(-p, v0[i][j + 1]); } } } } } rep(i, H) { rep(j, W) { P("%3d ", v0[i][j]); } P("\n"); } const int INF = 1000000005; vector> v1(H, vector(W, INF)); v1[H - 1][W - 1] = g[H - 1][W - 1] + 1; { rep(ii, H) rep(jj, W) { auto i = H - 1 - ii; auto j = W - 1 - jj; auto p = v1[i][j]; if(p > 0) { if(i > 0) { if(p > g[i - 1][j]) { v1[i - 1][j] = max(p - g[i - 1][j], g[i - 1][j] + 1); } else { v1[i - 1][j] = g[i - 1][j] + 1; } } if(j > 0) { if(p > g[i][j - 1]) { v1[i][j - 1] = min(v1[i][j - 1], p - g[i][j - 1]); v1[i][j - 1] = max(v1[i][j - 1], g[i][j - 1] + 1); } else { if(v1[i][j - 1] == INF) v1[i][j - 1] = g[i][j - 1] + 1; else v1[i][j - 1] = max(v1[i][j - 1], g[i][j - 1] + 1); } } } } } P("----\n"); rep(i, H) { rep(j, W) { P("%3d ", v1[i][j]); } P("\n"); } if(v0[H - 1][W - 1] >= v1[H - 1][W - 1]) { LP; cout << "Yes" << endl; return 0; } rep(i, H) rep(j, W) { if(v0[i][j] >= 0) continue; auto p = -v0[i][j]; if(i < H - 1 && p >= v1[i + 1][j]) { LP; cout << "Yes" << endl; return 0; } if(j < W - 1 && p >= v1[i][j + 1]) { LP; cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }