Submission
Status:
[PPPPPPPPTSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Quaoar
Problemset: อัศวินขี่ม้าขาว
Language: cpp
Time: 1.092 second
Submitted On: 2026-01-01 12:52:18
#include <iostream>
#include <algorithm>
using namespace std;
int n , m;
int map[1001][1001];
int r[1001];
int c[1001];
int len = 0;
int hp = 0;
int mnhp = 1;
int mxhp = -2147483647;
void re(int x , int y){
if (x >= n || y >= m) return;
r[len] = x;
c[len] = y;
len++;
if (x == n - 1 && y == m - 1) {
for (int i = 0; i < len; i++){
hp += map[r[i]][c[i]];
mnhp = min(hp , mnhp);
//out << map[r[i]][c[i]] << " " ;
}
//cout << "mnhp : " << mnhp ;
mxhp = max(mnhp , mxhp);
hp = 0;
mnhp = 1;
//cout << "\n";
} else {
re(x, y + 1);
re(x + 1, y);
}
len--;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0 ; i < n ; i++){
for (int j = 0 ; j < m ; j++){
cin >> map[i][j];
}
}
re(0,0);
if (mxhp > 0){
cout << mxhp;
} else {
cout << (mxhp * -1) + 1;
}
}