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

#include <bits/stdc++.h>

using namespace std;

#define send                                                                   \\
  { ios_base::sync_with_stdio(false); }
#define help                                                                   \\
  {                                                                            \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define f first
#define s second
#define getunique(v)                                                           \\
  {                                                                            \\
    sort(v.begin(), v.end());                                                  \\
    v.erase(unique(v.begin(), v.end()), v.end());                              \\
  }
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.f << ", " << p.s << ")";
}
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}

mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */

void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}

const lld pi = 3.14159265358979323846;
// const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;

ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1000625;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;

vector<ll> in_row[300005];
multiset<ll> best;

void upd(ll pos, ll delta) {
  best.erase(best.find(c[pos]));
  c[pos] += delta;
  best.insert(c[pos]);
}

void solve(int tc = 0) {
  cin >> n >> m >> k;

  for (ll i = 0; i < m; i++) {
    c[i] = 0;
    best.insert(0);
  }

  for (ll i = 0; i < k; i++) {
    cin >> x >> y;
    --x;
    --y;
    in_row[x].push_back(y);
    upd(y, 1);
  }

  ans = 0;
  for (ll i = 0; i < n; i++) {
    ll cur = in_row[i].size();

    for (ll x : in_row[i]) {
      upd(x, -1);
    }

    if (best.size()) {
      cur += *best.rbegin();
    }

    ans = max(ans, cur);

    for (ll x : in_row[i]) {
      upd(x, 1);
    }
  }

  cout << ans << '\\n';
}

int main() {
#ifdef galen_colin_local
  auto begin = std::chrono::high_resolution_clock::now();
#endif

  send help

#ifndef galen_colin_local
  // usaco("cowland");
#endif

      // usaco("cowland");

      int tc = 1;
  // cin >> tc;
  for (int t = 0; t < tc; t++)
    solve(t);

#ifdef galen_colin_local
  auto end = std::chrono::high_resolution_clock::now();
  cout << setprecision(4) << fixed;
  // cout << "Execution time: " <<
  // std::chrono::duration_cast<std::chrono::duration<double>>(end -
  // begin).count() << " seconds" << endl;
#endif
}


Error: 0

Fixed submission:

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

void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  int a[h + 2][w + 2];
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++)
      a[i][j] = 0;
  }
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    a[b - 1][c - 1] = 1;
  }
  long long int rowMax = 0;
  int rowInd = 0;
  for (int i = 0; i < h; i++) {
    long long int count = 0;
    for (int j = 0; j < w; j++) {
      count += a[i][j];
    }
    if (count > rowMax) {
      rowMax = count;
      rowInd = i;
    }
  }

  long long int colMax = 0;
  for (int i = 0; i < w; i++) {
    long long int count = 0;
    for (int j = 0; j < h; j++) {
      if (j == rowInd) {
        continue;
      }
      count += a[j][i];
    }
    if (count > colMax) {
      colMax = count;
    }
  }

  long long int ans = colMax + rowMax;

  cout << ans << "\\n";
}

int main() {
  solve();

  return 0;
}