-
Notifications
You must be signed in to change notification settings - Fork 0
/
1146. Maximum Sum.cpp.bak
61 lines (59 loc) · 1.24 KB
/
1146. Maximum Sum.cpp.bak
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
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cassert>
#include <cstring>
using namespace std;
int sum[101][101];
int A[101][101];
int sums(int i,int j,int k,int l){
int suma=0;
for(int ia=i;ia<=k;ia++){
if(j-1>=0)
suma+=(sum[ia][l]-sum[ia][j-1]);
else
suma+=(sum[ia][l]-0);
}
return suma;
}
int main()
{
int N;
scanf("%d",&N);
memset(sum,0,sizeof(sum));
memset(A,0,sizeof(A));
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
scanf("%d",&A[i][j]);
for(int i=0;i<N;i++)
sum[i][0]=A[i][0];
for(int i=0;i<N;i++)
for(int j=1;j<N;j++)
sum[i][j]=sum[i][j-1]+A[i][j];
int result=0;
int maxa=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
for(int k=i;k<N;k++){
for(int l=j;l<N;l++){
int ans=sums(i,j,k,l);
if(ans>maxa)
maxa=ans;
}
}
}
}
printf("%d\n",maxa);
return 0;
}