This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
const int N = 130;
int a[N][N], s[N][N];
int main() {
int n, res = INT_MIN;
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 - 1][j] + a[i][j]; // 利用一维前缀和,把当前第j列前面的1~j-1列的值,累加和压缩到第j列,每列都是如此处理
}
// O(N^3)算法
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
int _s = 0;
for (int k = 1; k <= n; k++) {
_s = max(_s, 0) + s[i][k] - s[j][k];
res = max(res, _s);
cout << res << '\n';
return 0;