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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define ff first
#define ss second
#define p pair<ll, ll>
#define pb push_back
#define endl '\\n'
#define w(t)                                                                   \\
  ll test;                                                                     \\
  cin >> test;                                                                 \\
  while (test--)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(0);
#define iof                                                                    \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define pi acos(-1)
const ll mxn = 3e5;
int main() {
  fast;
  ll h, m, w;
  cin >> h >> w >> m;
  map<p, ll> mp;
  map<ll, ll> row, col;
  ll rmax = 0, cmax = 0;
  ll r = 0, c = 0;
  for (ll i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    mp[{a, b}] = 1;
    row[a]++;
    if (row[a] > rmax) {
      rmax = row[a];
      r = a;
    }
    col[b]++;
    if (col[b] > cmax) {
      cmax = col[b];
      c = b;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= w; i++) {
    if (mp[{r, i}])
      ans = max(ans, (rmax + col[i] - 1));
    else
      ans = max(ans, rmax + col[i]);
  }
  for (ll i = 1; i <= h; i++) {
    if (mp[{i, c}])
      ans = max(ans, (cmax + row[i] - 1));
    else
      ans = max(ans, cmax + row[i]);
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define ff first
#define ss second
#define p pair<ll, ll>
#define pb push_back
#define endl '\\n'
#define w(t)                                                                   \\
  ll test;                                                                     \\
  cin >> test;                                                                 \\
  while (test--)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(0);
#define iof                                                                    \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define pi acos(-1)
const ll mxn = 3e5;
bool cmp(p a, p b) { return a.ss > b.ss; }
int main() {
  fast;
  ll h, m, w;
  cin >> h >> w >> m;
  vector<ll> adj[h + 10];
  vector<ll> vis(h + 10);
  map<ll, ll> row, col;
  while (m--) {
    ll a, b;
    cin >> a >> b;
    adj[b].pb(a);
    row[a]++;
    col[b]++;
  }
  vector<p> vec;
  for (auto i : col) {
    vec.pb({i.ff, i.ss});
  }
  sort(vec.begin(), vec.end(), cmp);
  ll ac = vec[0].ss;
  for (auto i : adj[vec[0].ff]) {
    if (!vis[row[i]]) {
      row[i]--;
      vis[row[i]] = 1;
    }
  }
  vec.clear();
  vector<p> v;
  for (auto i : row) {
    v.pb({i.ff, i.ss});
  }
  sort(v.begin(), v.end(), cmp);
  ll ar = v[0].ss;
  ll ans = ac + ar;
  cout << ans << endl;
}