#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; const int INF = 1e9; const ll inf = 1LL<<60; void solve() { int h, w; cin >> h >> w; vector> a(h, vector(w)); for (int i=0; i> a[i][j]; queue> q; q.push({0, 0, a[0][0], 0}); while (q.size()) { auto now = q.front(); q.pop(); int i = now[0], j = now[1]; if (i == h-1 && j == w-1) { cout << "Yes" << '\n'; return; } ll lv = now[2], state = now[3]; if (i + 1 < h) { if (lv > a[i+1][j]) { q.push({i+1, j, lv+a[i+1][j], state}); } else { if (state == 1) continue; if (i+1 == h-1 && j == w-1) continue; q.push({i+1, j, lv, state+1}); } } if (j+1 < w) { if (lv > a[i][j+1]) { q.push({i, j+1, lv+a[i][j+1], state}); } else { if (state == 1) continue; if (i == h-1 && j+1 == w-1) continue; q.push({i, j+1, lv, state+1}); } } } cout << "No" << '\n'; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); // int t; cin >> t; /*while (t--)*/ solve(); }