#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; 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]; } queue> que; que.push({0, a[0][0], 0}); vector> vis(h, vector(w, 0)); vis[0][0] = a[0][0]; int dx[2] = {0, 1}; int dy[2] = {1, 0}; bool flag = false; while (!que.empty()) { auto &[id, at, dt] = que.front(); que.pop(); int x = id / w; int y = id % w; if (x == h - 1 && y == w - 1) { flag = true; break; } for (int i = 0; i < 2; i++) { ll AT = at, DT = dt; int nx = x + dx[i]; int ny = y + dy[i]; if (0 > nx || nx >= h || 0 > ny || ny >= w) continue; //cout << nx << ' ' << ny << ' ' << AT << ' ' << DT << endl; if (a[nx][ny] >= AT) { if (nx == h - 1 && ny == w - 1) continue; else if (DT > 0) continue; else DT += 1; } else { AT += a[nx][ny]; } if (vis[nx][ny] >= AT) continue; vis[nx][ny] = AT; que.push({nx * w + ny, AT, DT}); } } cout << (flag ? "Yes": "No") << endl; return 0; }