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

// To debug :  g++ -g file.cpp -o code
// to flush output : fflush(stdout) or cout.flush()
// cout<<setprecision(p)<<fixed<<var
// use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
// take care of precedence rule of operators
// do not forget to change the sizes of arrays and value of contants and other
// things after debugging

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, n) for (i = a; i < n; ++i)
#define irep(i, n, a) for (i = n; i > a; --i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x) (ll)(x.size())

// comment the below if not required

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second

#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

// cout<<"Case #"<<c<<": "<<ans<<"\\n" ;

int r, c, q, u, v, ans, mxr, mxc, i, Q;

const int N = 3e5 + 1;

int mu[N], mv[N];

map<pair<int, int>, int> m;

vector<int> vr, vc;

int main() {
  IOS;

  cin >> r >> c >> q;

  Q = q;

  while (q--) {
    cin >> u >> v;
    ++mu[u], ++mv[v];
    mxr = max(mxr, mu[u]);
    mxc = max(mxc, mv[v]);
    m[{u, v}] = 1;
  }

  ans = mxr + mxc - 1;

  for (i = 1; i <= r; ++i)
    if (mxr == mu[i])
      vr.pb(i);

  for (i = 1; i <= c; ++i)
    if (mxc == mv[i])
      vc.pb(i);

  if ((SZ(vr) * SZ(vc)) > Q)
    cout << (ans + 1);
  else {
    for (auto u : vr)
      for (auto v : vc) {
        if (!m[{u, v}]) {
          cout << (ans + 1);
          return 0;
        }
      }

    cout << ans;
  }

  return 0;
}

Error: WA

Fixed submission:

// To debug :  g++ -g file.cpp -o code
// to flush output : fflush(stdout) or cout.flush()
// cout<<setprecision(p)<<fixed<<var
// use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
// take care of precedence rule of operators
// do not forget to change the sizes of arrays and value of contants and other
// things after debugging

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, n) for (i = a; i < n; ++i)
#define irep(i, n, a) for (i = n; i > a; --i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x) (ll)(x.size())

// comment the below if not required

/*

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/

#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

vector<vector<int>> v;

const int N = 3e5 + 1;

int r[N], c[N];

int main() {

  int n, m, q, i, j, u1, v1, ans = 0;

  cin >> n >> m >> q;

  v.resize(n + 1, vector<int>(m + 1, 0));

  rep(i, 1, n + 1) rep(j, 1, m + 1) v[i][j] = 0;

  while (q--) {
    cin >> u1 >> v1;
    ++v[u1][v1];
  }

  rep(i, 1, m + 1) {
    int sum = 0;

    rep(j, 1, n + 1) { sum += v[j][i]; }

    c[i] = sum;
  }

  rep(i, 1, n + 1) {
    int sum = 0;

    rep(j, 1, m + 1) { sum += v[i][j]; }

    r[i] = sum;
  }

  rep(i, 1, n + 1) rep(j, 1, m + 1) { ans = max(ans, r[i] + c[j] - v[i][j]); }

  cout << ans;

  return 0;
}