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

// FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define FOR(i, n) for (ll i = 0; i < n; i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int, int>
#define pll pair<long, long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d)                                                         \\
  cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define PI 3.1415926535897932384626433832795
#define fix(f, n) fixed << setprecision(n) << f
#define all(x) x.begin(), x.end()
#define rev(p) reverse(p.begin(), p.end());
#define endl "\\n"
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine()                                                          \\
  cout << "\\n\\nTime elapsed: " << (clock() - begtime) * 1000 / CLOCKS_PER_SEC  \\
       << " ms\\n\\n";
// #define _Find_next
// #define _Find_first

ll newmod(ll a, ll b) { return ((a % b) + b) % b; }

ll powM(ll a, ll b, ll m) {
  if (a <= 0)
    return 0;
  a %= m;
  if (!b)
    return 1;
  ll ans = 1LL;
  while (b) {
    if (b & 1)
      ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b) {

  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;
}

template <typename T, typename F> void chmax(T &a, F b) {
  if (b > a)
    a = b;
}

template <typename T, typename F> void chmin(T &a, F b) {
  if (b < a)
    a = b;
}

const ll N = 1e5 + 5;

int main() {

  IOS;

  ll h, w, m;
  cin >> h >> w >> m;

  set<pll> s;

  vpll row(h + 1);
  vpll col(w + 1);

  while (m--) {
    ll x, y;

    cin >> x >> y;
    s.insert({x, y});
    row[x].ff++;
    col[y].ff++;
  }

  for (int i = 1; i <= h; i++)
    row[i].ss = i;

  for (int j = 1; j <= w; j++)
    col[j].ss = j;

  sort(all(row));
  sort(all(col));

  rev(row);
  rev(col);

  ll ans = 0;

  for (int i = 0; i < h; i++) {
    ll temp = col[0].ff + row[i].ff;
    if (s.count({row[i].ss, col[0].ss}))
      temp--;
    // if(temp==4)d1(i);
    chmax(ans, temp);
  }

  for (int i = 0; i < w; i++) {
    ll temp = row[0].ff + col[i].ff;
    if (s.count({row[0].ss, col[i].ss}))
      temp--;
    chmax(ans, temp);
  }

  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

// FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define FOR(i, n) for (ll i = 0; i < n; i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int, int>
#define pll pair<long, long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d)                                                         \\
  cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define PI 3.1415926535897932384626433832795
#define fix(f, n) fixed << setprecision(n) << f
#define all(x) x.begin(), x.end()
#define rev(p) reverse(p.begin(), p.end());
#define endl "\\n"
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine()                                                          \\
  cout << "\\n\\nTime elapsed: " << (clock() - begtime) * 1000 / CLOCKS_PER_SEC  \\
       << " ms\\n\\n";
// #define _Find_next
// #define _Find_first

ll newmod(ll a, ll b) { return ((a % b) + b) % b; }

ll powM(ll a, ll b, ll m) {
  if (a <= 0)
    return 0;
  a %= m;
  if (!b)
    return 1;
  ll ans = 1LL;
  while (b) {
    if (b & 1)
      ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b) {

  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;
}

template <typename T, typename F> void chmax(T &a, F b) {
  if (b > a)
    a = b;
}

template <typename T, typename F> void chmin(T &a, F b) {
  if (b < a)
    a = b;
}

const ll N = 1e5 + 5;

int main() {

  IOS;

  ll h, w, m;
  cin >> h >> w >> m;

  vvl grid(h, vl(w));

  while (m--) {
    ll x, y;
    cin >> x >> y;
    grid[x - 1][y - 1] = 1;
  }

  vl pr(h), pc(w);

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j])
        pr[i]++, pc[j]++;
    }
  }

  ll ans = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ll temp = pr[i] + pc[j];
      if (grid[i][j])
        temp--;
      chmax(ans, temp);
    }
  }

  cout << ans;

  return 0;
}