-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaximumSumOJ.cpp
69 lines (59 loc) · 1.46 KB
/
maximumSumOJ.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
while (true)
{
int n = - 1;
cin >> n;
if (n == -1)
{
break;
}
vector<vector<int>> a(n, vector<int>(n));
vector<vector<int>> dp(n, vector<int>(n + 1));
for (int y = 0; y <= n - 1; ++y)
{
int sum = 0;
dp[y][0] = 0;
for (int x = 0; x <= n - 1; ++x)
{
cin >> a[y][x];
sum += a[y][x];
dp[y][x + 1] = sum;
}
}
int maxSum = INT_MIN;
for (int y0 = 0; y0 <= n - 1; ++y0)
{
for (int x0 = 0; x0 <= n - 1; ++x0)
{
for (int x1 = x0 + 1; x1 <= n; ++x1)
{
int sum = 0;
for (int y1 = y0; y1 <= n - 1; ++y1)
{
sum += dp[y1][x1] - dp[y1][x0];
maxSum = max(maxSum, sum);
}
}
}
}
cout << maxSum << '\n';
}
cout.flush();
return 0;
}