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

#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace std::chrono;

typedef long long int ll;

#define MOD (ll)(1e9 + 7)
#define endl "\\n"
#define pb push_back
#define TEST_CASES                                                             \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define forn(i, a, n) for (int i = a; i < n; ++i)
#define f first
#define s second
#define all(x) x.begin(), x.end()

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif

ll powD(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    x = (x * x) % MOD;
    y = y >> 1;
  }
  return res;
}
/*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
int main() {
  // freopen("dislodging_logs_validation_input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> x(h, 0), y(w, 0);
  map<pair<int, int>, bool> targets;
  vector<pair<int, int>> t;
  forn(i, 0, m) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    targets[{u, v}] = 1;
    x[u]++;
    y[v]++;
    t.push_back({u, v});
  }
  int maxx = *max_element(all(x));
  int maxy = *max_element(all(y));
  vector<int> xcandi, ycandi;
  forn(i, 0, h) {
    if (maxx == x[i])
      xcandi.push_back(i);
  }
  forn(j, 0, w) {
    if (maxy == y[j])
      ycandi.push_back(j);
  }
  ll a = xcandi.size();
  ll b = ycandi.size();
  if (a * b > m) {
    cout << maxy + maxx << endl;
  } else {
    bool flag = 0;
    for (auto i : xcandi) {
      for (auto j : ycandi) {
        if (!targets[{i, j}])
          flag = 1;
      }
    }
    if (flag)
      cout << maxx + maxy << endl;
    else
      cout << maxx + maxy - 1 << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace std::chrono;

typedef long long int ll;

#define MOD (ll)(1e9 + 7)
#define endl "\\n"
#define pb push_back
#define TEST_CASES                                                             \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define forn(i, a, n) for (int i = a; i < n; ++i)
#define f first
#define s second
#define all(x) x.begin(), x.end()

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif

ll powD(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    x = (x * x) % MOD;
    y = y >> 1;
  }
  return res;
}
vector<int> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
/*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
int main() {
  // freopen("dislodging_logs_validation_input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> x(h, 0), y(w, 0);
  vector<vector<bool>> targets(h, vector<bool>(w, 0));
  forn(i, 0, m) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    targets[u][v] = 1;
    x[u]++;
    y[v]++;
  }
  int ans = -1;
  forn(i, 0, h) {
    forn(j, 0, w) {
      int candi = x[i] + y[j] - targets[i][j];
      ans = max(ans, candi);
    }
  }
  cout << ans << endl;
}