#include #include #include using namespace std; using namespace atcoder; #define print(n) cout << (n) << endl #define fprint(n) cout << setprecision(16) << (n) << endl #define ceil_div(a, b) (((a) - 1) / (b) + 1) #define rep(i, l, n) for (int i = (l); i < (n); i++) #define itrep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++) #define ite(i, a) for (auto& i : a) #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound #define lbi(A, x) (ll)(lb(all(A), x) - A.begin()) #define ubi(A, x) (ll)(ub(all(A), x) - A.begin()) using str = string; using ll = long long; using Pair = pair; using mint = modint1000000007; using Mint = modint998244353; template using V = vector; template using VV = V >; template using PQ = priority_queue, greater >; template using PQR = priority_queue; template using BIT = fenwick_tree; const ll INF = 4611686018427387903; const int inf = 2147483647; const ll mod = 1000000007; const ll MOD = 998244353; template inline V getList(int n) { V res(n); rep(i, 0, n) { cin >> res[i]; }return res; } template inline VV getGrid(int m, int n) { VV res(m, V(n)); rep(i, 0, m) { res[i] = getList(n); }return res; } template inline void prints(V& vec) { if (vec.size() == 0)return; cout << vec[0]; rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; } inline V dtois(string& s) { V vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; } inline V atois(string& s) { V vec = {}; ite(e, s) { vec.push_back(e - 'a'); } return vec; } inline V Atois(string& s) { V vec = {}; ite(e, s) { vec.push_back(e - 'A'); } return vec; } int main(void) { int h, w; cin >> h >> w; VV a = getGrid(h, w); VV > dp(h, VV(w, V(2))); dp[0][0][0] = a[0][0]; deque > que = { {0,0,a[0][0],0} }; int m = 0; while (que.empty() == false) { ll x = que[0][0], y = que[0][1], t = que[0][2], c = que[0][3]; que.pop_front(); V dx = { 1,0 }, dy = { 0,1 }; rep(i, 0, 2) { ll nx = x + dx[i], ny = y + dy[i]; if (nx < 0 or nx >= h or ny < 0 or ny >= w) { continue; } if (t > a[nx][ny] and t + a[nx][ny] > dp[nx][ny][c]) { dp[nx][ny][c] = t + a[nx][ny]; if (nx + ny >= m) { que.push_back({ nx, ny, t + a[nx][ny], c }); m++; } else { que.push_front({ nx, ny, t + a[nx][ny], c }); } } else if (c == 0 and (nx != h - 1 or ny != w - 1) and t > dp[nx][ny][1]) { dp[nx][ny][1] = t; if (nx + ny >= m) { que.push_back({ nx, ny, t, 1 }); m++; } else { que.push_front({ nx, ny, t, 1 }); } } } } if (dp[h - 1][w - 1][0] + dp[h - 1][w - 1][1] > 0) { print("Yes"); } else { print("No"); } return 0; }