#include // #include using namespace std; // using namespace atcoder; using ll = long long; using ld = long double; using P = pair; using vl = vector; const int INF = 1e9; const ll LINF = 1e18; const double eps = 1e-10; #define fi first #define se second #define eb emplace_back #define rep(i,n) for(ll i = 0; i < (ll)(n); ++i) #define srep(i, s, n) for (ll i = s; i < (ll)(n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define fore(i,x) for(auto &i:x) #define ALL(x) x.begin(),x.end() #define RALL(x) x.rbegin(),x.rend() #define sz(x) (ll)x.size() #define dame { puts("-1"); return;} #define yes { puts("Yes"); return;} #define no { puts("No"); return;} #define ret(x) { cout<<(x)<<'\n'; return;} bool is_pop(ll hash, ll d){return (hash>>d)&1;} template using vc = vector; template using vv = vc>; template using PQ = priority_queue,greater>; templatevoid in(T&... a) { (cin >> ... >> a); } void out() { cout << '\n'; } templatevoid out(const T& a, const Ts&... b) { cout << a;(cout << ... << (cout << ' ', b));cout << '\n'; } template< typename T >istream &operator>>(istream &is, vector< T > &v){for(T &in : v) is >> in;return is;} template< typename T >ostream &operator<<(ostream &os, const vector< T > &v){for(int i = 0; i < (int) v.size(); i++) {os << v[i] << (i + 1 != (int) v.size() ? " " : "");}return os;} templateconstexpr auto min(T... a) { return min(initializer_list>{a...}); } templateconstexpr auto max(T... a) { return max(initializer_list>{a...}); } templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b a(h,vl(w)); in(a); vv dp(h,vv(w,vl(2))); dp[0][0][0] = a[0][0]; rep(i,h) rep(j,w) rep(k,2) { ll now = dp[i][j][k]; if(i + 1 < h) { if(now > a[i+1][j]) chmax(dp[i+1][j][k],now+a[i+1][j]); else if(k == 0) chmax(dp[i+1][j][1],now); } if(j + 1 < w) { if(now > a[i][j+1]) chmax(dp[i][j+1][k],now+a[i][j+1]); else if(k == 0) chmax(dp[i][j+1][1],now); } } bool flg = false; rep(k,2) if(dp[h-1][w-1][k] > a[h-1][w-1]) flg = true; if(flg) yes else no }