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

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

#define ll                                                                     \\
  long long // data types used often, but you don't want to type them time by
            // time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0); // to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x, j, n) for (int x = j; x < n; x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll, ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;

bool isprime(ll n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (ll i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0)
      return false;
  }
  return true;
}

ll modexp(ll a, ll b, ll m) {
  ll r = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1)
      r = (r * a) % m;
    b = b >> 1;
    a = (a * a) % m;
  }
  return r % m;
}

struct CustomCompare {
  bool operator()(const int &lhs, const int &rhs) { return lhs < rhs; }
};

bool comp(pair<ll, ll> a, pair<ll, ll> b) { return a.fi >= b.fi; }

ll builtin_popcount(ll x) {
  ll cnt = 0;
  for (ll i = 60; i >= 0; i--) {
    if ((1LL << i) & x)
      cnt++;
  }
  return cnt;
}

ll addmod(ll a, ll b) {
  a %= mod;
  b %= mod;
  return (a + b) % mod;
}
ll mulmod(ll a, ll b) {
  a %= mod;
  b %= mod;
  return (a * b) % mod;
}
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, m, points;
  cin >> n >> m >> points;
  map<pi, ll> mp;
  vi row(n + 1), col(m + 1);
  rep(i, 0, points) {
    ll x, y;
    cin >> x >> y;
    mp[{x, y}]++;
    row[x]++, col[y]++;
  }
  ll r = *max_element(all(row)), c = *max_element(all(col));
  vi arr, brr;
  rep(i, 1, n + 1) {
    if (row[i] == r)
      arr.pb(i);
  }
  rep(i, 1, m + 1) {
    if (col[i] == c)
      brr.pb(i);
  }

  ll ans = r + c;
  bool flag = false;
  for (auto x : arr) {
    for (auto y : brr) {
      if (mp.find({x, y}) == mp.end()) {
        flag = true;
        break;
      }
    }
    if (flag)
      break;
  }
  if (!flag)
    ans--;
  cout << ans << "\\n";
  return 0;
}
/*
1
4
1 2
2 3
3 4
2
2 2
*/


Error: 0

Fixed submission:

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

#define ll                                                                     \\
  long long // data types used often, but you don't want to type them time by
            // time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0); // to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x, j, n) for (int x = j; x < n; x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll, ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;

bool isprime(ll n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (ll i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0)
      return false;
  }
  return true;
}

ll modexp(ll a, ll b, ll m) {
  ll r = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1)
      r = (r * a) % m;
    b = b >> 1;
    a = (a * a) % m;
  }
  return r % m;
}

struct CustomCompare {
  bool operator()(const int &lhs, const int &rhs) { return lhs < rhs; }
};

bool comp(pair<ll, ll> a, pair<ll, ll> b) { return a.fi >= b.fi; }

ll builtin_popcount(ll x) {
  ll cnt = 0;
  for (ll i = 60; i >= 0; i--) {
    if ((1LL << i) & x)
      cnt++;
  }
  return cnt;
}

ll addmod(ll a, ll b) {
  a %= mod;
  b %= mod;
  return (a + b) % mod;
}
ll mulmod(ll a, ll b) {
  a %= mod;
  b %= mod;
  return (a * b) % mod;
}
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, m, q;
  cin >> n >> m >> q;
  vi row(n), col(m);
  ll dp[n][m];
  memset(dp, 0, sizeof(dp));
  rep(i, 0, q) {
    ll r, c;
    cin >> r >> c;
    r--, c--;
    dp[r][c] = 1;
    row[r]++, col[c]++;
  }
  ll ans = 0;
  rep(i, 0, n) {
    rep(j, 0, m) {
      ll val = row[i] + col[j];
      if (dp[i][j])
        val--;
      ans = max(ans, val);
    }
  }
  cout << ans << endl;
  return 0;
}
/*
1
4
1 2
2 3
3 4
2
2 2
*/