#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include using ll = long long; using ld = long double; using namespace std; // using namespace atcoder; using P = pair; using Graph = vector>; using Priority = priority_queue, greater>;// 昇順 using Priority_pair = priority_queue, greater

>; // using mint_17 = modint1000000007; // using mint = modint998244353; #define mod 1000000007 #define MAX_WIDTH 60 #define MAX_HEIGHT 60 #define INF 1e18 #define MOD 998244353 #define PI 3.141592653589793 #define rep(i, a, b) for(ll i=(a);i<(b);i++) #define rrep(i, a, b) for(ll i=(a);i>=(b);i--) #define fore(i, a) for(auto &i: a) #define all(v) (v).begin(), (v).end() #define YES(a) cout << ((a) ? "YES" : "NO") << endl #define Yes(a) cout << ((a) ? "Yes" : "No") << endl #define pb(a) push_back(a) #define vi vector #define vll vector #define vs vector #define vc vector #define vp vector> #define mll map #define msl map #define COUT(n) cout << (n) << endl #define isInGrid(n, h, w) (0 <= (n) && (n) < (h) && 0 <= (n) && (n) < (w)) template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } // int vx[] = {1,0,-1,0}, vy[] = {0,1,0,-1}; ll H, W, A[510][510]; // bool reached[510][510], ans = false; // int vx[] = {1, 0}, vy[] = {0, 1}; // void dfs(ll y, ll x, ll c, ll now) { // if(y >= H-1 && x >= W-1) { // ans = true; // return; // } // reached[y][x] = true; // rep(i, 0, 2) { // ll ny = y+vy[i], nx = x+vx[i]; // if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue; // if(reached[ny][nx]) continue; // if(A[ny][nx] >= now) { // if(c == 0 && ny != H-1 && nx != W-1) { // dfs(ny,nx,c+1, now); // } else { // continue; // } // } else { // dfs(ny,nx,c,now + A[ny][nx]); // } // } // return; // } ll dp[510][510][5]; // bool reached[510][510]; // void bfs(ll y, ll x) { // queue> que; // que.push({y, x}); // int vy[] = {0,1}, vx[] = {1,0}; // while(!que.empty()) { // ll y = que.front().first, x = que.front().second; // que.pop(); // rep(i, 0, 2) { // ll ny = y+vy[i], nx = x+vx[i]; // if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue; // que.push({ny, nx}); // } // } // } int main() { cin >> H >> W; rep(i, 0, H) { rep(j, 0, W) { cin >> A[i][j]; dp[i][j][0] = dp[i][j][1] = -INF; } } dp[0][0][0] = A[0][0]; rep(i, 0, H) { rep(j, 0, W) { rep(k, 0, 2) { // 右 if(j+1 < W) { if(dp[i][j][k] <= A[i][j+1]) { if(k == 0 && i != H-1 && j != W-1) { chmax(dp[i][j+1][k+1], dp[i][j][k]); } } else { chmax(dp[i][j+1][k], dp[i][j][k] + A[i][j+1]); } } if(i+1 < H) { if(dp[i][j][k] <= A[i+1][j]) { if(k == 0 && i != H-1 && j != W-1) { chmax(dp[i+1][j][k+1], dp[i][j][k]); } } else { chmax(dp[i+1][j][k], dp[i][j][k] + A[i+1][j]); } } } } } // cout << dp[H-1][W-1][0] << " " << dp[H-1][W-1][1] << endl; Yes(dp[H-1][W-1][0] > A[H-1][W-1] || dp[H-1][W-1][1] > A[H-1][W-1]); return 0; }