1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n; int g[N][N];
int main() { cin >> n; for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= n; j ++ ) { cin >> g[i][j]; g[i][j] += g[i - 1][j]; }
int res = INT_MIN; for (int i = 1; i <= n; i ++ ) for (int j = i; j <= n; j ++ ) { int last = 0; for (int k = 1; k <= n; k ++ ) { last = max(last, 0) + g[j][k] - g[i - 1][k]; res = max(res, last); } }
cout << res << endl; return 0; }
|