-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathH.cpp
More file actions
48 lines (40 loc) · 1.08 KB
/
Copy pathH.cpp
File metadata and controls
48 lines (40 loc) · 1.08 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
#define SIZE 100
int input[SIZE][SIZE];
int sum[SIZE];
int solve(int N) {
int max_ending_here, max_so_far, maximum = INT_MIN;
for (int startx = 0; startx < N; startx++) {
memset(sum, 0, N * sizeof(int));
for (int x = startx; x < N; x++) {
max_ending_here = 0;
max_so_far = INT_MIN;
for (int y = 0; y < N; y++) {
sum[y] += input[x][y];
max_ending_here = max(0, max_ending_here + sum[y]);
max_so_far = max(max_so_far, max_ending_here);
}
maximum = max(maximum, max_so_far);
}
}
return maximum;
}
int main() {
/* freopen("H.in","r",stdin);
freopen("H.out","w",stdout);*/
int tc;
cin>>tc;
while(tc--){
int N, num;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &num);
input[i][j] = num;
}
}
printf("%d\n", solve(N));
}
return 0;
}