Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int N = 300000;
void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> row, col;
  map<pair<int, int>, int> mm;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    row[x]++;
    col[y]++;
    mm[{x, y}] = 1;
  }
  int rowmax = -1, colmax = -1;
  map<int, vector<int>> rr, cc;
  for (auto [key, value] : row) {
    if (value == rowmax) {
      rr[value].push_back(key);
      rowmax = value;
    } else if (value > rowmax) {
      rr[value].clear();
      rr[value].push_back(key);
      rowmax = value;
    }
  }
  for (auto [key, value] : col) {
    if (value == colmax) {
      cc[value].push_back(key);
      colmax = value;
    } else if (value > colmax) {
      cc[value].clear();
      cc[value].push_back(key);
      colmax = value;
    }
  }
  int maxi = colmax + rowmax;
  for (auto i : rr[rowmax]) {
    for (int j : cc[colmax]) {
      if (mm[{i, j}] != 1) {
        cout << maxi << "\\n";
        return;
      }
    }
  }
  cout << maxi - 1 << "\\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int N = 300000;
void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> row, col;
  map<pair<int, int>, int> mm;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    row[x]++;
    col[y]++;
    mm[{x, y}] = 1;
  }
  int maxi = -1;
  for (auto i : row) {
    for (auto j : col) {
      if (i.second + j.second >= maxi) {
        int count = i.second + j.second;
        if (mm[{i.first, j.first}] == 1)
          count--;
        maxi = max(maxi, count);
      }
    }
  }
  // debug() << imie(maxi);
  cout << maxi << "\\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}