-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00108.cpp
More file actions
55 lines (52 loc) · 917 Bytes
/
00108.cpp
File metadata and controls
55 lines (52 loc) · 917 Bytes
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
49
50
51
52
53
54
55
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int temp[101],matrix[105][105],n;
int kadane()
{
int sum(0),s=-1,m(-12800);
for(int i=0;i<n;i++)
{
sum+=temp[i];
m=max(sum,m);
if(sum<0)
{
sum=0;
s=i+1;
}
}
return m;
}
void solve()
{
int sum = -99999999;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&matrix[i][j]);
}
}
for(int l=0;l<n;l++)
{
fill_n(temp,n,0);
for(int r=l;r<n;r++)
{
for(int row=0;row<n;row++)
{
temp[row]+=matrix[r][row];
}
sum = max(sum,kadane());
}
}
printf("%d\n",sum);
}
int main()
{
while(cin>>n)
{
solve();
}
return 0;
}