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

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

#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1
#define endl "\\n"

const int maxn = 5e5 + 10;
const int mod = 998244353;
const double pi = acos(-1);

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int qpow(int a, int n) {
  int b = 1;
  while (n) {
    if (n & 1)
      b = a * b % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return b;
}

class Prime_Number {
public:
  int prime[maxn], s, v[maxn];
  void prime_init(int n) {
    for (int i = 2; i <= n; i++) {
      if (!v[i]) {
        prime[s++] = i;
        for (int j = 1; j * i <= n; j++)
          v[i * j] = 1;
      }
    }
  }
};

//**************************
int x, y, r[maxn], c[maxn];
vector<int> v[maxn], rr, cc;
set<pair<int, int>> st;
void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  int mr = 0, mc = 0;
  for (int i = 0; i < m; i++) {
    sll2(x, y);
    st.insert(make_pair(x, y));
    r[x]++;
    c[y]++;
    if (mr < r[x]) {
      mr = r[x];
      rr.clear();
      rr.pb(x);
    } else if (mr == r[x]) {
      rr.pb(x);
    }
    if (mc < c[y]) {
      mc = c[y];
      cc.clear();
      cc.pb(y);
    } else if (mc == c[y]) {
      cc.pb(y);
    }
  }
  for (int i : rr)
    for (int j : cc) {
      if (st.count(make_pair(i, j)))
        continue;
      else {
        cout << mr + mc;
        return;
      }
    }
  cout << mr + mc - 1;
}
signed main() {
  solve();
  return 0;
}


Error: WA

Fixed submission:

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

#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1
#define endl "\\n"

const int maxn = 5e1 + 10;
const int mod = 998244353;
const double pi = acos(-1);

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int qpow(int a, int n) {
  int b = 1;
  while (n) {
    if (n & 1)
      b = a * b % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return b;
}

class Prime_Number {
public:
  int prime[maxn], s, v[maxn];
  void prime_init(int n) {
    for (int i = 2; i <= n; i++) {
      if (!v[i]) {
        prime[s++] = i;
        for (int j = 1; j * i <= n; j++)
          v[i * j] = 1;
      }
    }
  }
};

//**************************
int x, y, r[maxn], c[maxn];
vector<int> v[maxn];
void solve() {
  int h, w, m;
  // set<pair<int, int>> st;
  cin >> h >> w >> m;
  int mr = 0, mc = 0;
  for (int i = 0; i < m; i++) {
    sll2(x, y);
    // st.insert(make_pair(x, y));
    r[x]++;
    c[y]++;
    v[x].pb(y);
    mr = max(r[x], mr);
    mc = max(mc, c[y]);
  }
  int k = mr + mc;
  int ans;
  for (int i = 1; i <= h; i++) {
    if (r[i] == mr)
      for (int j = 1; j <= w; j++) {
        if (c[j] == mc) {
          // if (st.count(make_pair(i, j)))
          int ok = 0;
          for (int l : v[i])
            if (l == j) {
              ok = 1;
              break;
            }
          ans = k - ok;
        }
      }
    if (ans == k)
      break;
  }
  cout << ans;
}
signed main() {
  solve();
  return 0;
}