Created
April 23, 2025 14:45
-
-
Save LautaroLasorsa/4bb12f1f4fe92abfd454a3f603be6a57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main(){ | |
int t; cin>>t; | |
while(t--){ | |
int n,m; | |
cin>>n>>m; | |
vector<vector<int> > mat(n, vector<int>(m)); | |
for(auto & fila : mat){ | |
for(auto & elem : fila){ | |
cin>>elem; | |
} | |
} | |
vector<vector<int> > dpmax(n, vector<int>(m,-1e9)); | |
vector<vector<int> > dpmin(n, vector<int>(m,1e9)); | |
dpmax[0][0] = dpmin[0][0] = mat[0][0]; | |
for(int i = 0; i <n;i++) for(int j = 0;j<m;j++){ | |
if(i==0 and j==0) continue; | |
if(i>0){ | |
dpmax[i][j] = max(dpmax[i][j], dpmax[i-1][j] + mat[i][j]); | |
dpmin[i][j] = min(dpmin[i][j], dpmin[i-1][j] + mat[i][j]); | |
} | |
if(j>0){ | |
dpmax[i][j] = max(dpmax[i][j], dpmax[i][j-1] + mat[i][j]); | |
dpmin[i][j] = min(dpmin[i][j], dpmin[i][j-1] + mat[i][j]); | |
} | |
} | |
if((n+m)%2==1 and dpmax[n-1][m-1] >=0 and dpmin[n-1][m-1]<=0){ | |
cout<<"YES"<<endl; | |
}else{ | |
cout<<"NO"<<endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment