-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path108.cpp
45 lines (40 loc) · 810 Bytes
/
108.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
/*
Author: Andreea Musat
10 Feb 2018
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, i, j, k, l;
int arr[100][100];
long max_subrect, tmp;
cin >> N;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
cin >> arr[i][j];
if (i > 0) arr[i][j] += arr[i - 1][j];
if (j > 0) arr[i][j] += arr[i][j - 1];
if (i > 0 and j > 0) arr[i][j] -= arr[i - 1][j - 1];
}
}
max_subrect = LONG_MIN;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
for (k = i; k < N; k++)
for (l = j; l < N; l++)
{
tmp = arr[k][l];
if (i > 0) tmp -= arr[i - 1][l];
if (j > 0) tmp -= arr[k][j - 1];
if (i > 0 and j > 0) tmp += arr[i - 1][j - 1];
if (tmp > max_subrect)
{
max_subrect = tmp;
}
}
cout << max_subrect << "\n";
return 0;
}