#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll inf = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int h, w; cin >> h >> w; auto a = vec2d(h, w, 0ll); for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin >> a[i][j]; } } auto dp = vec3d(h, w, 2, -inf); dp[0][0][0] = a[0][0]; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ for(int k = 0; k < 2; k++){ if(i != h-1 && a[i+1][j] < dp[i][j][k]){ chmax(dp[i+1][j][k], dp[i][j][k]+a[i+1][j]); } if(i != h-1 && k == 0 && a[i+1][j] >= dp[i][j][k]){ chmax(dp[i+1][j][1], dp[i][j][k]); } if(j != w-1 && a[i][j+1] < dp[i][j][k]){ chmax(dp[i][j+1][k], dp[i][j][k]+a[i][j+1]); } if(j != w-1 && k == 0 && a[i][j+1] >= dp[i][j][k]){ chmax(dp[i][j+1][1], dp[i][j][k]); } } } } if(dp[h-1][w-1][0] > a[h-1][w-1] || dp[h-1][w-1][1] > a[h-1][w-1]){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }