-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax_target.cpp
More file actions
67 lines (57 loc) · 1.38 KB
/
max_target.cpp
File metadata and controls
67 lines (57 loc) · 1.38 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
66
67
#include<bits/stdc++.h>
#define llu long long int
using namespace std;
int main(){
int m,n,targets;
cin>>m>>n>>targets;
set<llu> values; // to store hash
int rows[m],cols[n];
memset(rows,0,sizeof(rows));
memset(cols,0,sizeof(cols));
for(int i=0;i<targets;i++){
int v1,v2;
cin>>v1>>v2;
llu hash=v1*1000000000+v2; // hash created
values.insert(hash);
rows[v1]++; // to find that which row has how many targets
cols[v2]++; // to find that which row has how many targets
}
// now we will find the maxTarget value
int maxX=INT_MIN,maxY=INT_MIN;
//maxX
for(int i=0;i<m;i++){
maxX=max(maxX,rows[i]);
}
//maxY
for(int i=0;i<n;i++){
maxY=max(maxY,cols[i]);
}
// now we will have candidate rows and cols which can be destroyed
vector<int> candX; vector<int> candY; int ind=0;
for(int i=0;i<m;i++){
if(rows[i]==maxX){
candX.push_back(i);
}
}
ind=0;
for(int i=0;i<n;i++){
if(cols[i]==maxY){
candY.push_back(i);
}
}
// in the above two loops we are having our candidates rows and cols;
int ans=maxX+maxY-1,flag=0;
for(int cx:candX){
for(int cy:candY){
llu hash=cx*1000000000+cy;
if(values.find(hash)==values.end()){
ans++;
flag=1; // if target is not here we add one and break from this and outer loop
break;
}
}
if(flag==1) break;
}
cout<<ans;
return 0;
}