//g++ 2.cpp -std=c++14 -O2 -I . #include using namespace std; #include using namespace atcoder; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using vld = vector; using vvld = vector; using vst = vector; using vvst = vector; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue,less> #define pq_small(T) priority_queue,greater> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int h,w; cin>>h>>w; vvll a(h,vll(w,0)),dp1(h,vll(w,0)),dp2(h,vll(w,0)); rep(i,0,h){ rep(j,0,w){ cin>>a[i][j]; } } dp1[0][0]=a[0][0]; rep(i,0,h){ rep(j,0,w){ if(ia[ni][nj]){ dp1[ni][nj]=max(dp1[ni][nj],dp1[i][j]+a[ni][nj]); } else if(ni+nj!=h+w-2){ dp2[ni][nj]=max(dp2[ni][nj],dp1[i][j]); } if(dp2[i][j]>a[ni][nj]){ dp2[ni][nj]=max(dp2[ni][nj],dp2[i][j]+a[ni][nj]); } } if(ja[ni][nj]){ dp1[ni][nj]=max(dp1[ni][nj],dp1[i][j]+a[ni][nj]); } else if(ni+nj!=h+w-2){ dp2[ni][nj]=max(dp2[ni][nj],dp1[i][j]); } if(dp2[i][j]>a[ni][nj]){ dp2[ni][nj]=max(dp2[ni][nj],dp2[i][j]+a[ni][nj]); } } } } if(dp1[h-1][w-1]==0&&dp2[h-1][w-1]==0){ cout<<"No\n"; } else{ cout<<"Yes\n"; } }