Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
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 {
#ifdef 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 pp(...) "\\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\\033[0m"
#define pp1(...)                                                               \\
  "\\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ << "]" << pp(x)
#define dg2(x, y) debug() << "[line : " << __LINE__ << "]" << pp(x) pp(y)
#define dg3(x, y, z)                                                           \\
  debug() << "[line : " << __LINE__ << "]" << pp(x) pp(y) pp(z)
#define dg4(w, x, y, z)                                                        \\
  debug() << "[line : " << __LINE__ << "]" << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin(), x.end()
#define clr(x, y) memset(x, y, sizeof x);
#define sz(x) (int)x.size()
template <typename T> void db(T x) { debug() << ">>> " << x; }
template <typename T> void db(T x, T y) {
  debug() << ">>> " << x << " , " << y;
}
template <typename T> void db(T x, T y, T z) {
  debug() << ">>> " << x << " , " << y << " , " << z;
}
template <typename T> void db(T x, T y, T z, T a) {
  debug() << ">>> " << x << " , " << y << " , " << z << " , " << a;
}
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R, C, M;
  cin >> R >> C >> M;

  vector<int> rsum(R, 0);
  vector<int> csum(C, 0);
  vector<pair<int, int>> P;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    rsum[h]++;
    csum[w]++;
    P.emplace_back(h, w);
  }
  int Rmax = *max_element(all(rsum));
  int Cmax = *max_element(all(csum));
  int t1 = 0, t2 = 0;
  for (int i = 0; i < R; i++) {
    if (rsum[i] == Rmax)
      t1++;
  }
  for (int i = 0; i < C; i++) {
    if (csum[i] == Cmax)
      t2++;
  }
  int t = t1 * t2;
  int ans = Rmax + Cmax;
  for (auto i : P) {
    if (rsum[i.first] == Rmax && csum[i.second] == Cmax) {
      t--;
    }
  }
  if (t == 0)
    ans--;
  cout << ans << '\\n';
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
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 {
#ifdef 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 pp(...) "\\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\\033[0m"
#define pp1(...)                                                               \\
  "\\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ << "]" << pp(x)
#define dg2(x, y) debug() << "[line : " << __LINE__ << "]" << pp(x) pp(y)
#define dg3(x, y, z)                                                           \\
  debug() << "[line : " << __LINE__ << "]" << pp(x) pp(y) pp(z)
#define dg4(w, x, y, z)                                                        \\
  debug() << "[line : " << __LINE__ << "]" << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin(), x.end()
#define clr(x, y) memset(x, y, sizeof x);
#define sz(x) (int)x.size()
template <typename T> void db(T x) { debug() << ">>> " << x; }
template <typename T> void db(T x, T y) {
  debug() << ">>> " << x << " , " << y;
}
template <typename T> void db(T x, T y, T z) {
  debug() << ">>> " << x << " , " << y << " , " << z;
}
template <typename T> void db(T x, T y, T z, T a) {
  debug() << ">>> " << x << " , " << y << " , " << z << " , " << a;
}
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;
vector<vector<int>> mat;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R, C, M;
  cin >> R >> C >> M;
  mat = vector<vector<int>>(R, vector<int>(C, 0));
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    mat[h][w]++;
  }
  vector<int> rsum(R, 0);
  vector<int> csum(C, 0);
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      rsum[i] += mat[i][j];
      csum[j] += mat[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      int x = rsum[i] + csum[j] - (mat[i][j] > 0);
      ans = max(ans, x);
    }
  }
  cout << ans << '\\n';
}