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

#include <bits/stdc++.h>
#define ll long long int
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define test(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define endl "\\n"
#define debug(x) cout << x << "\\n"
#define pb push_back
#define mp make_pair
#define MEMS(x, t) memset(x, t, sizeof(x))
#define mod 1000000007
#define forn(i, n) for (ll i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
// #define map map<ll,ll>
#define fi first
#define se second
#define set set<ll>
#define pp pair<ll, ll>
using namespace std;
bool sortbysec(const pp &a, const pp &b) { return (a.second < b.second); }
// ll r[h], c[w];
// ll mat[300000][300000];
int main() {
  fastio;
  ll h, w, m;
  cin >> h >> w >> m;
  ll r[h], c[w];
  // mat[h][w];
  map<pp, ll> mat;
  forn(i, h) r[i] = 0;
  forn(i, w) c[i] = 0;
  ll x, y, mr = 0, mc = 0, ir, ic;
  forn(i, m) {
    cin >> x >> y;
    x--;
    y--;
    mat[{x, y}] = 1;
    r[x]++, c[y]++;
    mr = max(r[x], mr);
    mc = max(c[y], mc);
  }
  bool f = false;
  vector<ll> vr, vc;
  forn(i, h) {
    if (r[i] == mr)
      vr.pb(i);
  }
  forn(i, w) {
    if (c[i] == mc)
      vc.pb(i);
  }
  ll ans = mr + mc;
  for (ll i = 0; i < vr.size(); i++) {
    for (ll j = 0; j < vc.size(); j++) {
      if (mat[{vr[i], vc[j]}] != 1) {
        // ans = mr + mc;
        f = true;
        break;
      }
    }
  }
  if (f)
    cout << ans;
  else
    cout << ans - 1;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define test(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define endl "\\n"
#define debug(x) cout << x << "\\n"
#define pb push_back
#define mp make_pair
#define MEMS(x, t) memset(x, t, sizeof(x))
#define mod 1000000007
#define forn(i, n) for (ll i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define map map<ll, ll>
#define fi first
#define se second
#define set set<ll>
#define pp pair<ll, ll>
using namespace std;
bool sortbysec(const pp &a, const pp &b) { return (a.second < b.second); }
// ll r[h], c[w];
int main() {
  fastio;
  ll h, w, m;
  cin >> h >> w >> m;
  ll r[h], c[w], mat[h][w];
  forn(i, h) r[i] = 0;
  forn(i, w) c[i] = 0;
  ll x, y, mr = 0, mc = 0, ir, ic;
  forn(i, m) {
    cin >> x >> y;
    x--;
    y--;
    mat[x][y] = 1;
    r[x]++, c[y]++;
    mr = max(r[x], mr);
    mc = max(c[y], mc);
    // mat[x-1][y-1] = 1;
  }
  bool f = false;
  vector<ll> vr, vc;
  forn(i, h) {
    if (r[i] == mr)
      vr.pb(i);
  }
  forn(i, w) {
    if (c[i] == mc)
      vc.pb(i);
  }
  // forn(i,h) cout << r[i] << " ";
  // cout << endl;
  // forn(i, w) cout << c[i] << " ";
  // cout << endl;
  // cout << mr << " " << mc << endl;
  ll ans = mr + mc;
  for (ll i = 0; i < vr.size(); i++) {
    for (ll j = 0; j < vc.size(); j++) {
      if (mat[vr[i]][vc[j]] != 1) {
        // ans = mr + mc;
        f = true;
        break;
      }
    }
  }
  if (f)
    cout << ans;
  else
    cout << ans - 1;
  // forn(i,h)
  // {
  //     forn(j, w)
  //     {
  //         if ( mat[i][j] == 1) temp = r[i] + c[j] - 1;
  //         else temp = r[i] + c[j];
  //         ans = max(temp, ans);
  //     }
  // }
  // cout << ans;
}