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

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vz;
typedef vector<vz> vvz;
typedef pair<ll, ll> pll;
#define sz(x) int((x).size())
#define fo(i, n) for (ll i = 0; i < (n); i++)
#define FO(i, a, b) for (ll i = (a); i != (b); i += (b) > (a) ? 1 : -1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define os(x) cout << x << ' '
#define on(x) cout << x << "\\n"
#define nl cout << "\\n"
#define maxe(x) max_element(all(x)) - (x).begin()
#define mine(x) min_element(all(x)) - (x).begin()
const ll P = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("C:\\\\Users\\\\ASISH\\\\Desktop\\\\coding\\\\input1.txt", "r", stdin);
  freopen("C:\\\\Users\\\\ASISH\\\\Desktop\\\\coding\\\\output1.txt", "w", stdout);
#endif

  int tc = 1;
  fo(q, tc) {
    ll h, w, m;
    cin >> h >> w >> m;

    map<pair<ll, ll>, ll> mp;

    vll cx(h + 1), cy(w + 1);

    fo(i, m) {
      ll x, y;
      cin >> x >> y;
      mp[{x, y}] = 1;
      cx[x]++;
      cy[y]++;
    }

    ll mx = 0, my = 0;
    fo(i, sz(cx)) { mx = max(mx, cx[i]); }
    fo(i, sz(cy)) { my = max(my, cy[i]); }

    vll vx, vy;
    fo(i, sz(cx)) {
      if (cx[i] == mx)
        vx.pb(i);
    }
    fo(i, sz(cy)) {
      if (cy[i] == my)
        vy.pb(i);
    }

    bool flag = 0;
    for (auto i : vx) {
      for (auto j : vy) {
        if (!mp[{i, j}]) {
          flag = 1;
          break;
        }
      }
      if (flag)
        break;
    }
    if (flag)
      on(min(mx + my, m));
    else
      on(min(mx + my - 1, m));
  }
  cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\\n";
  return 0;
}

Error: WA

Fixed submission:

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vz;
typedef vector<vz> vvz;
typedef pair<ll, ll> pll;
#define sz(x) int((x).size())
#define fo(i, n) for (ll i = 0; i < (n); i++)
#define FO(i, a, b) for (ll i = (a); i != (b); i += (b) > (a) ? 1 : -1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define os(x) cout << x << ' '
#define on(x) cout << x << "\\n"
#define nl cout << "\\n"
#define maxe(x) max_element(all(x)) - (x).begin()
#define mine(x) min_element(all(x)) - (x).begin()
const ll P = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("C:\\\\Users\\\\ASISH\\\\Desktop\\\\coding\\\\input1.txt", "r", stdin);
  freopen("C:\\\\Users\\\\ASISH\\\\Desktop\\\\coding\\\\output1.txt", "w", stdout);
#endif

  int tc = 1;
  fo(q, tc) {
    ll h, w, m;
    cin >> h >> w >> m;

    vector<vector<bool>> mp(h + 1, vector<bool>(w + 1));

    vll cx(h + 1), cy(w + 1);

    fo(i, m) {
      ll x, y;
      cin >> x >> y;
      mp[x][y] = 1;
      cx[x]++;
      cy[y]++;
    }

    ll mx = 0, my = 0;
    fo(i, sz(cx)) { mx = max(mx, cx[i]); }
    fo(i, sz(cy)) { my = max(my, cy[i]); }

    vll vx, vy;
    fo(i, sz(cx)) {
      if (cx[i] == mx)
        vx.pb(i);
    }
    fo(i, sz(cy)) {
      if (cy[i] == my)
        vy.pb(i);
    }

    bool flag = 0;
    for (auto i : vx) {
      for (auto j : vy) {
        if (!mp[i][j]) {
          flag = 1;
          break;
        }
      }
      if (flag)
        break;
    }
    if (flag)
      on(min(mx + my, m));
    else
      on(min(mx + my - 1, m));
  }
  cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\\n";
  return 0;
}