Submission
Status:
[PPPPPPPPPP-SSSS]
Score: 0
User: devilpoohs
Problemset: อัศวินขี่ม้าขาว
Language: cpp
Time: 0.063 second
Submitted On: 2025-03-30 15:47:25
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
int ar[n][m];
int dp[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>ar[i][j];
}
}
dp[0][0]=ar[0][0];
for(int i=1;i<n;i++){
ar[i][0]=ar[i-1][0]+ar[i][0];
dp[i][0]=min(dp[i-1][0],ar[i][0]);
}
for(int j=1;j<m;j++){
ar[0][j]=ar[0][j-1]+ar[0][j];
dp[0][j]=min(dp[0][j-1],ar[0][j]);
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
ar[i][j]=max(ar[i-1][j]+ar[i][j],ar[i][j-1]+ar[i][j]);
}
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
int ans=INT_MIN;
if(dp[i-1][j]>ar[i][j]){
ans=ar[i][j];
}else{
ans=max(ans,dp[i-1][j]);
}
if(dp[i][j-1]>ar[i][j]){
ans=ar[i][j];
}else{
ans=max(ans,dp[i][j-1]);
}
dp[i][j]=ans;
}
}
// for(int i=)0
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// cout<<dp[i][j]<<' ';
// }
// cout<<'\n';
// }
// for(int i)
if(dp[n-1][m-1]>0){
cout<<'1';
}else
cout<<abs(dp[n-1][m-1])+1;
return 0;
}
/*
4 3
-3 -6 -3
2 2 -3
-8-8-8
1 1 1
2 3
-3 -6 -3
2 2 -3
g++ tod.cpp -o tod.exe; if ($?) { .\tod.exe }
*/