#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; const int INF = 1e9; const ll inf = 1LL<<60; template bool chmin(T& x, const T& y){ if(x <= y) return false; x = y; return true; } template bool chmax(T& x, const T& y){ if(x >= y) return false; x = y; return true; } void solve() { int h, w; cin >> h >> w; vector> a(h, vector(w)); for (int i=0; i> a[i][j]; vector>> dp(h, vector>(w, vector(2, -inf))); dp[0][0][0] = a[0][0]; for (int i=0; i= 0) { if (dp[i-1][j][0] > a[i][j]) { chmax(dp[i][j][0], dp[i-1][j][0] + a[i][j]); } else { chmax(dp[i][j][1], dp[i-1][j][0]); } if (dp[i-1][j][1] > a[i][j]) { chmax(dp[i][j][1], dp[i-1][j][1] + a[i][j]); } } if (j-1 >= 0) { if (dp[i][j-1][0] > a[i][j]) { chmax(dp[i][j][0], dp[i][j-1][0] + a[i][j]); } else { chmax(dp[i][j][1], dp[i][j-1][0]); } if (dp[i][j-1][1] > a[i][j]) { chmax(dp[i][j][1], dp[i][j-1][1] + a[i][j]); } } } // for (int i=0; i a[h-1][w-1] ? "Yes" : "No") << '\n'; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); // int t; cin >> t; /*while (t--)*/ solve(); }