-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10827.cpp
80 lines (70 loc) · 1.28 KB
/
10827.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <vector>
#include <cstdio>
#define foi( i , n , k ) for( int i = n ; i < k ; ++i )
using namespace std;
int sumArr(vector<int> &arr,int tam)
{
int totMay=-9999999;
foi( n , 0 , tam )
{
int may=-9999999;
int sum=0;
foi( i , n , n+tam )
{
sum+=arr[i];
if(may<sum)
may=sum;
if(sum<0)
sum=0;
}
if(totMay<may)
totMay=may;
}
return totMay;
}
int maxSum( vector< vector< int > > &mat,int tam)
{
int may,mayTot,sum;
mayTot=-9999999;
foi( k , 0 , tam )
{
vector<int> arr(2*tam,0);
foi(m , k ,k+ tam )
{
foi( n , 0 ,2* tam )
{
arr[n]+=mat[m][n];
}
may=sumArr(arr,tam);
if(mayTot<may)
mayTot=may;
}
}
return mayTot;
}
int main()
{
int t;
scanf("%d",&t);
while( t-- )
{
int tam;
scanf("%d",&tam);
vector< vector< int > > mat(2*tam,vector<int>(tam*2));
foi( i , 0 , tam )
{
foi( j , 0 , tam )
{
int num;
scanf("%d",&num);
mat[i][j]=num;
mat[i][j+tam]=num;
mat[i+tam][j]=num;
mat[i+tam][j+tam]=num;
}
}
printf("%d\n",maxSum(mat,tam) );
}
return 0;
}