Problem: E - Bomber
My Approach: I maintain a frequency array for the x and y coordinates separately. Then I choose the x-coordinate with the maximum frequency and add it to the sum. Then I decrement the frequency of the y-coordinates with that particular x-coordinate (the one with the maximum frequency) with the help of a map which maps the y-coordinates to the x-coordinate.
CODE:
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
int main() {
FASTIO
int h, w, m;
cin >> h >> w >> m;
vector<int> freqx(h+1,0), freqy(w+1,0);
map<int,vector<int>> mxy;
for(int i=0; i<m; i++) {
int x, y;
cin >> x >> y;
freqx[x]++, freqy[y]++;
mxy[x].push_back(y);
}
int sum = 0, maxX = 0;
for(int i=1; i<=h; i++) {
if(freqx[i] > sum) {
sum = freqx[i];
maxX = i;
}
}
for(int y : mxy[maxX]) {
freqy[y]--;
}
sum += *max_element(freqy.begin(), freqy.end());
cout << sum << "\n";
return 0;
}
Problem with the code: The above code gets an AC in all of the test cases except for the 5 test cases on which it gives a WA. Can anyone please help me figure out the problem with the code?