-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1676D_XSum.cpp
More file actions
59 lines (59 loc) · 1.47 KB
/
Copy path1676D_XSum.cpp
File metadata and controls
59 lines (59 loc) · 1.47 KB
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
#include <bits/stdc++.h> //Problem-1676D
using namespace std;
#define ll long long
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
while (t--)
{
ll n, m, i, j, ans = 0;
cin >> n >> m;
vector<vector<ll>> v(n, vector<ll>(m));
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
cin >> v[i][j];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
ll x = 1, y = 1, sum = v[i][j];
while ((i + x) <= (n - 1) && (j + y) <= (m - 1))
{
sum += v[i + x][j + y];
x++;
y++;
}
x = 1, y = 1;
while ((i - x) >= 0 && (j + y) <= (m - 1))
{
sum += v[i - x][j + y];
x++;
y++;
}
x = 1, y = 1;
while ((i + x) <= (n - 1) && (j - y) >= 0)
{
sum += v[i + x][j - y];
x++;
y++;
}
x = 1, y = 1;
while ((i - x) >= 0 && (j - y) >= 0)
{
sum += v[i - x][j - y];
x++;
y++;
}
ans = max(ans, sum);
}
}
cout << ans << endl;
}
return 0;
}