文件目录

#include <bits/stdc++.h>
using namespace std;
int n, a[105][105], s[105][105];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> a[i][j];
            s[i][j] = s[i][j - 1] + a[i][j]; // 前缀和
        }
    }
    int ans = -2147483648;
    for (int l = 0; l < n; l++)
    {
        for (int r = l + 1; r <= n; r++)
        {
            int sum = 0;
            for (int i = 1; i <= n; i++)
            {
                sum += s[i][r] - s[i][l];
                if (ans < sum)
                    ans = sum;
                if (sum < 0)
                    sum = 0; // 必须后变0,有可能全负
            }
        }
    }
    cout << ans;
    return 0;
}