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

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

// #define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

  vll by(m), bx(m);
  vector<P> tgt;
  rep(i, m) {
    cin >> by[i] >> bx[i];
    by[i]--;
    bx[i]--;
    tgt.emplace_back(by[i], bx[i]);
  }

  sort(all(tgt));

  vll yy(h), xx(w);
  rep(i, m) {
    yy[by[i]]++;
    xx[bx[i]]++;
  }

  auto my = *max_element(all(yy));
  auto mx = *max_element(all(xx));

  ll ans = my + mx - 1;

  vll candy;
  vll candx;

  rep(i, h) {
    if (yy[i] == my) {
      candy.push_back(i);
    }
  }

  rep(i, w) {
    if (xx[i] == mx) {
      candx.push_back(i);
    }
  }

  for (auto y : candy) {
    for (auto x : candx) {
      if (!binary_search(all(tgt), make_pair(y, x))) {
        ans++;
        goto finish;
      }
    }
  }

finish:

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

// #define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

  vll y(m), x(m);
  rep(i, m) {
    cin >> y[i] >> x[i];
    y[i]--;
    x[i]--;
  }
  vll yy(h), xx(h);
  rep(i, m) {
    yy[y[i]]++;
    xx[x[i]]++;
  }

  auto ity = max_element(all(yy));
  auto itx = max_element(all(xx));

  ll ans = *ity + *itx;

  rep(i, m) {
    if (y[i] == *ity && x[i] == *itx) {
      ans--;
    }
  }

  cout << ans << endl;
  return 0;
}