-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1676D.cpp
52 lines (43 loc) · 849 Bytes
/
1676D.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
#include <algorithm>
#include <iostream>
void solve() {
int n, m;
std::cin >> n >> m;
int c[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
std::cin >> c[i][j];
int b = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int t = 0;
int di = 0, dj = 0;
if (i > j)
di = i - j;
else
dj = j - i;
for (int k = 0; k + di < n && k + dj < m; k++)
t += c[k + di][k + dj];
di = 0;
dj = 0;
if (i > m - j - 1)
di = i - (m - j - 1);
else
dj = m - j - 1 - i;
for (int k = 0; k + di < n && m - k - dj - 1 >= 0; k++)
t += c[k + di][m - k - dj - 1];
t -= c[i][j];
b = std::max(t, b);
}
}
std::cout << b << std::endl;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int t;
std::cin >> t;
while (t--)
solve();
return 0;
}