-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2033b.cpp
More file actions
55 lines (50 loc) · 1.22 KB
/
2033b.cpp
File metadata and controls
55 lines (50 loc) · 1.22 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
#include <bits/stdc++.h>
using namespace std;
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
#define F first
#define S second
#define cases int _; cin >> _; while(_--)
typedef long long ll;
typedef unsigned long long uint;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef set<int> si;
void solve() {
int a; cin >> a;
vector<vector<int>> A(a, vector<int>(a));
for(int i = 0; i < a; i++) {
for(int j = 0; j < a; j++) {
cin >> A[i][j];
}
}
int ans = 0;
// Process MAIN DIAGONALS (top-left to bottom-right)
// Start from first row
for(int i = 0; i < a; i++) {
int x = 0, y = i;
int min_number = 0;
while(x < a && y < a) {
if(A[x][y] < 0) min_number = min(min_number, A[x][y]);
x++; y++;
}
ans -= min_number;
}
// Start from first column (excluding the main diagonal)
for(int i = 1; i < a; i++) {
int x = i, y = 0;
int min_number = 0;
while(x < a && y < a) {
if(A[x][y] < 0) min_number = min(min_number, A[x][y]);
x++; y++;
}
ans -= min_number;
}
cout << ans << '\n';
}
int main() {
cases {
solve();
}
return 0;
}