gmx0424 @ 2023-10-20 20:43:45
#include<bits/stdc++.h>
using namespace std;
const int maxn = 130;
int n, a[maxn][maxn], sum[maxn][maxn];
int main () {
cin >> n;
for (int i = 1; i <= n; i++ ) {
for (int j = 1; j <= n; j++ ) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++ ) {
for (int j = 1; j <= n; j++ ) {
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
}
}
int ans = -0x3f3f3f3f;
for (int len = 1; len <= n; len++ ) {
for (int i = 1; i + len - 1<= n; i++ ) {
for (int j = 1; j + len - 1<= n; j++ ) {
int ii = i + len - 1;
int jj = j + len - 1;
int tmp = sum[ii][jj] - sum[i - 1][jj] - sum[ii][j - 1] + sum[i - 1][j - 1];
ans = max (ans, tmp);
}
}
}
cout << ans;
}