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

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define gap ' '
#define EPS 1e-9
#define P_INF 2e9 + 17
#define N_INF -2e9 - 17
#define MOD 1000000007
#define PI 2 * acos(0.0)
#define All(x) x.begin(), x.end()
#define Mem(Name, type) memset(Name, type, sizeof(Name))

template <typename T> T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template <typename T> T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
  for (auto ob : v)
    os << ob << " ";
  return os;
}

template <typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
  for (auto ob : v)
    os << ob.first << " : " << ob.second << std::endl;
  return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class EBomber {
public:
  void solve(std::istream &in, std::ostream &out) {
    int n, m, k, Cmaxi = 0, Rmaxi = 0;
    in >> n >> m >> k;
    vector<int> row(n + 2), colum(m + 2);
    set<pair<int, int>> s;
    for (int i = 0; i < k; ++i) {
      int x, y;
      in >> x >> y;
      row[x]++;
      colum[y]++;
      Cmaxi = max(Cmaxi, colum[y]);
      Rmaxi = max(Rmaxi, row[x]);
      s.insert({x, y});
    }
    vector<int> co;
    for (int i = 1; i < m + 1; ++i) {
      if (colum[i] == Cmaxi) {
        co.push_back(i);
      }
    }
    for (int i = 1; i < n + 1; ++i) {
      if (row[i] == Rmaxi) {
        for (int t : co) {
          if (s.find({i, t}) == s.end()) {
            out << Rmaxi + Cmaxi << endl;
            return;
          }
        }
      }
    }
    out << Rmaxi + Cmaxi - 1 << endl;
  }
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  EBomber solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Error: 0

Fixed submission:

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define gap ' '
#define EPS 1e-9
#define P_INF 2e9 + 17
#define N_INF -2e9 - 17
#define MOD 1000000007
#define PI 2 * acos(0.0)
#define All(x) x.begin(), x.end()
#define Mem(Name, type) memset(Name, type, sizeof(Name))

template <typename T> T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template <typename T> T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
  for (auto ob : v)
    os << ob << " ";
  return os;
}

template <typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
  for (auto ob : v)
    os << ob.first << " : " << ob.second << std::endl;
  return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class EBomber {
public:
  void solve(std::istream &in, std::ostream &out) {
    int n, m, k;
    in >> n >> m >> k;
    vector<int> row(n + 2), colum(m + 2);
    vector<vector<bool>> g(n + 2, vector<bool>(m + 2));
    for (int i = 0; i < k; ++i) {
      int x, y;
      in >> x >> y;
      row[x]++;
      colum[y]++;
      g[x][y] = true;
    }
    int ans = N_INF;
    for (int i = 1; i < n + 1; ++i) {
      for (int j = 1; j < m + 1; ++j) {
        if (g[i][j]) {
          ans = max(ans, row[i] + colum[j] - 1);
        } else {
          ans = max(ans, row[i] + colum[j]);
        }
      }
    }
    out << ans << endl;
  }
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  EBomber solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}