-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpizzabox.cpp
61 lines (58 loc) · 1.45 KB
/
pizzabox.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
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
ifstream inStream;
int numTestCases;
inStream.open("input.txt");
if(inStream.fail())
{
cerr << "Input file opening failed.\n";
exit(1);
}
inStream >> numTestCases;
for (int i = 0; i<numTestCases; i++){
int n, m, o;
inStream >> n >> m;
int box[1000][1000];
bool flags[1000][1000] = {0};
for (int i = 0; i<n; i++){
for (int j = 0; j<m; j++){
inStream >> o;
box[i][j] = o;
}
}
for (int i = 0; i<n; i++){
int flag = 0, max = 0;
for (int j = 0; j<m; j++){
if (max < box[i][j]){
max = box[i][j];
flag = j;
}
}
flags[i][flag] = true;
}
for (int i = 0; i<m; i++){
int flag = 0, max = 0;
for (int j = 0; j<n; j++){
if (max < box[j][i]){
max = box[j][i];
flag = j;
}
}
flags[flag][i] = true;
}
long long count = 0;
for (int i = 0; i<n; i++){
for (int j = 0; j<m; j++){
if (!flags[i][j]){
count += box[i][j];
}
}
}
cout << count <<endl;
}
inStream.close();
}