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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define mp make_pair
#define pb push_back
#define er erase
#define cl clear
#define sw swap
#define br break
#define ct continue
#define rt return
#define xx exit(0)
#define yy cout << "Yes\\n"
#define nn cout << "No\\n"
#define x first
#define y second
#define fo(i, a, b) for (int i = a; i < b; i++)
using namespace std;
struct st {};
bool cmp() { return 1; }
int go() { return 0; }
void recur() {}
void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  int a[h + 1], b[w + 1];
  for (int i = 0; i <= h; i++)
    a[i] = 0;
  for (int i = 0; i <= w; i++)
    b[i] = 0;
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < m; i++) {
    int p, q;
    cin >> p >> q;
    mp[{p, q}] = 1;
    a[p]++;
    b[q]++;
  }
  int ma = 0, mb = 0;
  vector<int> vec, wec;
  for (int i = 1; i <= h; i++) {
    if (a[i] > ma) {
      vec.cl();
      vec.pb(i);
      ma = a[i];
    } else if (a[i] == ma) {
      vec.pb(i);
    }
  }
  for (int i = 1; i <= w; i++) {
    if (b[i] > mb) {
      wec.cl();
      wec.pb(i);
      mb = b[i];
    } else if (b[i] == mb) {
      wec.pb(i);
    }
  }
  // cout<<endl<<endl<<endl;
  for (auto &i : vec) {
    for (auto &j : wec) {
      if (!mp[{i, j}]) {
        cout << ma + mb;
        rt;
      }
      // cout<<i<<' '<<j<<endl;
    }
  }
  cout << ma + mb - 1;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  fo(i, 0, t) solve();
}

Error: WA

Fixed submission:

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define mp make_pair
#define pb push_back
#define er erase
#define cl clear
#define sw swap
#define br break
#define ct continue
#define rt return
#define xx exit(0)
#define yy cout << "Yes\\n"
#define nn cout << "No\\n"
#define x first
#define y second
#define fo(i, a, b) for (int i = a; i < b; i++)
using namespace std;
struct st {};
bool cmp() { return 1; }
int go() { return 0; }
void recur() {}
void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  int a[h + 1], b[w + 1];
  for (int i = 0; i <= h; i++)
    a[i] = 0;
  for (int i = 0; i <= w; i++)
    b[i] = 0;
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < m; i++) {
    int p, q;
    cin >> p >> q;
    mp[{p, q}] = 1;
    a[p]++;
    b[q]++;
  }
  int ma = 0, mb = 0;
  vector<int> vec, wec;
  for (int i = 1; i <= h; i++) {
    if (a[i] > ma) {
      vec.cl();
      vec.pb(i);
      ma = a[i];
    } else if (a[i] == ma) {
      vec.pb(i);
    }
  }
  for (int i = 1; i <= w; i++) {
    if (a[i] > mb) {
      wec.cl();
      wec.pb(i);
      mb = b[i];
    } else if (b[i] == mb) {
      wec.pb(i);
    }
  }
  for (auto &i : vec) {
    for (auto &j : wec) {
      if (!mp[{i, j}]) {
        cout << ma + mb;
        rt;
      }
    }
  }
  cout << ma + mb - 1;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  fo(i, 0, t) solve();
}