-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2033B.cpp
More file actions
65 lines (48 loc) · 1.26 KB
/
Copy path2033B.cpp
File metadata and controls
65 lines (48 loc) · 1.26 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
60
61
62
63
64
65
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define umap unordered_map
#define f(i, x, n) for(ll i = x; i < n; i++)
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main() {
optimize();
ll t;
cin >> t;
while (t--) {
ll n;
cin >> n;
ll arr[n+1][n+1];
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
cin >> arr[i][j];
}
}
vector<ll> maxes;
for (ll i = n; i >= 1; i--) {
ll temp = i, j = 1, min = 0;
while (temp <= n) {
if (arr[temp][j] < min) min = arr[temp][j];
temp++;
j++;
}
if (min < 0) maxes.pb(min);
}
for (ll j = n; j >= 2; j--) {
ll temp = j, i = 1, min = 0;
while (temp <= n) {
if (arr[i][temp] < min) min = arr[i][temp];
temp++;
i++;
}
if (min < 0) maxes.pb(min);
}
ll ans = 0;
for (auto it : maxes) {
ans -= it;
}
cout << ans << endl;
}
}