-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHE-JUNEEASY-1.cpp
69 lines (64 loc) · 1.43 KB
/
HE-JUNEEASY-1.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
// https://www.hackerearth.com/challenges/competitive/july-easy-20/algorithm/kshitiz-and-matrix-7ddc9719/
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin) ;
freopen("output.txt", "w", stdout) ;
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL) ; cout.tie(NULL) ;
int t; cin >> t;
while (t--) {
long long int n, m; cin >> n >> m;
long long int arr[n][m];
long long int minVal = 1, maxVal = INT_MIN;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
long long int x; cin >> x;
arr[i][j] = x;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
long long int x = arr[i][j];
if (x > maxVal) maxVal = x;
if (x <= minVal) minVal = x;
}
}
long long int minRow, minCol, maxRow, maxCol;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] == minVal) {
minRow = i;
minCol = j;
}
if (arr[i][j] == maxVal) {
maxRow = i;
maxCol = j;
}
}
}
for (int i = 0; i < m; i++) {
arr[minRow][i] = -1;
}
for (int i = 0; i < n; i++) {
arr[i][minCol] = -1;
}
for (int i = 0; i < m; i++) {
arr[maxRow][i] = -1;
}
for (int i = 0; i < n; i++) {
arr[i][maxCol] = -1;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] == -1) continue;
ans++;
}
}
cout << ans << "\n";
}
return 0 ;
}