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

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

/*
#include <boost/multiprecision/cpp_dec_float.hpp>
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i, s, e) for ((i) = (s); (i) < (e); (i)++)
#define RREP(i, s, e) for ((i) = ((s)-1); (i) >= (e); (i)--)
#define FOR(i, n) for ((i) = (0); (i) < (n); (i)++)
#define RFOR(i, n) for ((i) = ((n)-1); (i) >= (0); (i)--)
#define MOD 1000000007
#define MAX 400000

signed main() {
  int H, W, M;
  cin >> H >> W >> M;
  int h[MAX], w[MAX];
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
  }

  int ans1 = 0;

  int cn[MAX + 1] = {0};
  for (int i = 0; i < M; i++) {
    cn[h[i]]++;
  }
  int mi = -1, mn = -1;
  for (int j = 1; j <= H; j++) {
    if (mn < cn[j]) {
      mn = cn[j];
      mi = j;
    }
  }
  for (int i = 1; i <= MAX; i++)
    cn[i] = 0;
  ans1 = mn;
  int mi2 = mi;
  mi = -1, mn = -1;
  for (int i = 0; i < M; i++) {
    if (mi2 != h[i])
      cn[w[i]]++;
  }
  mi = -1, mn = -1;
  for (int j = 1; j <= W; j++) {
    if (mn < cn[j]) {
      mn = cn[j];
      mi = j;
    }
  }
  ans1 += mn;
  for (int i = 1; i <= MAX; i++)
    cn[i] = 0;
  int ans2 = 0;

  for (int i = 0; i < M; i++) {
    cn[w[i]]++;
  }
  mi = -1, mn = -1;
  for (int j = 1; j <= W; j++) {
    if (mn < cn[j]) {
      mn = cn[j];
      mi = j;
    }
  }
  for (int i = 1; i <= MAX; i++)
    cn[i] = 0;
  ans2 = mn;
  mi2 = mi;
  mi = -1, mn = -1;
  for (int i = 0; i < M; i++) {
    if (mi2 != w[i])
      cn[h[i]]++;
  }
  mi = -1, mn = -1;
  for (int j = 1; j <= H; j++) {
    if (mn < cn[j]) {
      mn = cn[j];
      mi = j;
    }
  }
  ans2 += mn;

  cout << max(ans1, ans2) << endl;
}


Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

/*
#include <boost/multiprecision/cpp_dec_float.hpp>
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i, s, e) for ((i) = (s); (i) < (e); (i)++)
#define RREP(i, s, e) for ((i) = ((s)-1); (i) >= (e); (i)--)
#define FOR(i, n) for ((i) = (0); (i) < (n); (i)++)
#define RFOR(i, n) for ((i) = ((n)-1); (i) >= (0); (i)--)
#define MOD 1000000007
#define MAX 3000

signed main() {
  int H, W, M;
  cin >> H >> W >> M;
  int h[MAX], w[MAX];
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
  }
  int ans1 = 0;

  int mi = -1, mn = -1;
  for (int i = 1; i <= H; i++) {
    int c = 0;
    for (int j = 0; j < M; j++) {
      if (i == h[j])
        c++;
    }
    if (mn < c) {
      mn = c;
      mi = i;
    }
  }
  ans1 = mn;
  int mi2 = mi;
  mi = -1, mn = -1;
  for (int i = 1; i <= W; i++) {
    int c = 0;
    for (int j = 0; j < M; j++) {
      if (i == w[j] && mi2 != h[j])
        c++;
    }
    if (mn < c) {
      mn = c;
      mi = i;
    }
  }
  ans1 += mn;

  int ans2 = 0;

  mi = -1, mn = -1;
  for (int i = 1; i <= W; i++) {
    int c = 0;
    for (int j = 0; j < M; j++) {
      if (i == w[j])
        c++;
    }
    if (mn < c) {
      mn = c;
      mi = i;
    }
  }
  ans2 = mn;
  mi2 = mi;
  mi = -1, mn = -1;
  for (int i = 1; i <= H; i++) {
    int c = 0;
    for (int j = 0; j < M; j++) {
      if (i == h[j] && mi2 != w[j])
        c++;
    }
    if (mn < c) {
      mn = c;
      mi = i;
    }
  }
  ans2 += mn;

  cout << max(ans1, ans2) << endl;
}