alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  set<pair<int, int>> targets;
  vector<int> hSum(H), wSum(W);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    targets.insert({x - 1, y - 1});
    hSum[x - 1]++;
    wSum[y - 1]++;
  }

  int maxWVal = 0, maxHVal = 0;
  vector<int> maxWs, maxHs;

  for (int i = 0; i < H; i++) {
    if (hSum[i] > maxHVal) {
      maxHs.clear();
      maxHs.push_back(i);
      maxHVal = hSum[i];
    } else if (hSum[i] == maxHVal) {
      maxHs.push_back(i);
    }
  }
  for (int j = 0; j < W; j++) {
    if (wSum[j] > maxWVal) {
      maxWs.clear();
      maxWs.push_back(j);
      maxWVal = wSum[j];
    } else if (wSum[j] == maxWVal) {
      maxWs.push_back(j);
    }
  }

  int ans = maxWVal + maxHVal - 1;
  bool ok = false;
  for (int w : maxWs) {
    for (int h : maxHs) {
      if (targets.find({h, w}) == targets.end()) {
        ans += 1;
        ok = true;
        break;
      }
    }
    if (ok)
      break;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<vector<bool>> arr(H, vector<bool>(W, 0));
  vector<int> hSum(H), wSum(W);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    arr[x - 1][y - 1] = 1;
    hSum[x - 1]++;
    wSum[y - 1]++;
  }

  int maxWVal = 0, maxHVal = 0;
  vector<int> maxW, maxH;

  for (int i = 0; i < H; i++) {
    if (hSum[i] > maxHVal) {
      maxH.clear();
      maxH.push_back(i);
      maxHVal = hSum[i];
    } else if (hSum[i] == maxHVal) {
      maxH.push_back(i);
    }
  }
  for (int j = 0; j < W; j++) {
    if (wSum[j] > maxWVal) {
      maxW.clear();
      maxW.push_back(j);
      maxWVal = wSum[j];
    } else if (wSum[j] == maxWVal) {
      maxW.push_back(j);
    }
  }

  int ans = 0;
  for (int w : maxW) {
    for (int h : maxH) {
      int tempAns = hSum[h] + wSum[w];
      if (arr[h][w])
        tempAns -= 1;
      ans = max(tempAns, ans);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<ll, ll>;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<ll> hc(h), wc(w);
  vector<P> v;
  map<P, int> ma;
  ll hmax = 0, wmax = 0;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    ma[make_pair(x, y)] = 1;
    hc[x]++;
    wc[y]++;
    hmax = max(hmax, hc[x]);
    wmax = max(wmax, wc[y]);
  }
  vector<int> vh, vw;
  rep(i, h) {
    if (hc[i] == hmax)
      vh.push_back(i);
  }
  rep(i, w) {
    if (wc[i] == wmax)
      vw.push_back(i);
  }
  ll max = vh.size() * vw.size();
  if (max > m) {
    cout << hmax + wmax << endl;
  } else {
    ll cnt = 0;
    for (int x : vh)
      for (int y : vw) {
        if (ma[make_pair(x, y)] == 1)
          cnt++;
      }
    if (cnt == max)
      cout << hmax + wmax - 1 << endl;
    else
      cout << hmax + wmax << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<int, int>;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hc(h), wc(w);
  vector<vector<ll>> v(h, vector<ll>(w, 0));
  ll hmax = 0, wmax = 0;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x][y]++;
    hc[x]++;
    wc[y]++;
    hmax = max(hmax, hc[x]);
    wmax = max(wmax, wc[y]);
  }
  vector<int> vh, vw;
  rep(i, h) {
    if (hc[i] == hmax)
      vh.push_back(i);
  }
  rep(i, w) {
    if (wc[i] == wmax)
      vw.push_back(i);
  }

  cout << hmax + wmax - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

int main() {
  ll H, W, M;
  cin >> H >> W >> M;

  vpll bomb;
  vll rcount(H + 1, 0);
  vll ccount(W + 1, 0);
  for (ll i = 0; i < M; i++) {
    ll tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    rcount[tmp1]++;
    ccount[tmp2]++;
    bomb.ADD(MP(tmp1, tmp2));
  }

  ll rmax = 0;
  vll rmaxindex;
  for (ll i = 1; i <= H; i++) {
    if (rmax < rcount[i]) {
      rmax = rcount[i];
      rmaxindex.resize(0);
      rmaxindex.ADD(i);
    } else if (rmax == rcount[i]) {
      rmaxindex.ADD(i);
    }
  }

  ll cmax = 0;
  vll cmaxindex;
  for (ll i = 1; i <= W; i++) {
    if (cmax < ccount[i]) {
      cmax = ccount[i];
      cmaxindex.resize(0);
      cmaxindex.ADD(i);
    } else if (cmax == ccount[i]) {
      cmaxindex.ADD(i);
    }
  }

  sort(bomb.begin(), bomb.end());

  ll result = rmax + cmax;
  bool isFound = false;
  for (auto x : rmaxindex) {
    for (auto y : cmaxindex) {
      if (binary_search(bomb.begin(), bomb.end(), MP(x, y))) {
        continue;
      } else {
        isFound = true;
        break;
      }
    }

    if (isFound) {
      break;
    }
  }
  cout << (isFound ? result : result - 1) << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

ll key(pll pl) { return (pl.first << 32) + pl.second; }

int main() {
  ll H, W, M;
  cin >> H >> W >> M;

  vpll bomb;
  vll rcount(H + 1, 0);
  vll ccount(W + 1, 0);
  for (ll i = 0; i < M; i++) {
    ll tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    rcount[tmp1]++;
    ccount[tmp2]++;
    bomb.ADD(MP(tmp1, tmp2));
  }

  ll rmax = 0;
  vll rmaxindex;
  for (ll i = 1; i <= H; i++) {
    if (rmax < rcount[i]) {
      rmax = rcount[i];
      rmaxindex.resize(0);
      rmaxindex.ADD(i);
    } else if (rmax == rcount[i]) {
      rmaxindex.ADD(i);
    }
  }

  ll cmax = 0;
  vll cmaxindex;
  for (ll i = 1; i <= H; i++) {
    if (cmax < ccount[i]) {
      cmax = ccount[i];
      cmaxindex.resize(0);
      cmaxindex.ADD(i);
    } else if (cmax == ccount[i]) {
      cmaxindex.ADD(i);
    }
  }

  sort(bomb.begin(), bomb.end());

  ll result = rmax + cmax;
  bool isFound = false;
  for (ll i = 0; i < rmaxindex.size(); i++) {
    for (ll j = 0; j < cmaxindex.size(); j++) {
      if (binary_search(bomb.begin(), bomb.end(),
                        MP(rmaxindex[i], cmaxindex[j]))) {
        continue;
      } else {
        isFound = true;
        break;
      }
    }

    if (isFound) {
      break;
    }
  }
  cout << (isFound ? result : result - 1) << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;

long long pointGenerator(int row, int column, int width) {
  return (1LL * row * width) + column;
}

vector<int> getMax(vector<int> &men) {
  int maxSize = 0;
  vector<int> ret;
  for (int &i : men)
    maxSize = max(maxSize, i);
  for (int i = 0; i < men.size(); i++) {
    if (maxSize == men[i])
      ret.push_back(i);
  }
  return ret;
}

int main() {

  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);

  vector<int> x(m), y(m);
  unordered_set<long long> coords;
  vector<int> menInRow(h, 0);
  vector<int> menInColumn(w, 0);

  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    x[i]--, y[i]--;
    coords.insert(pointGenerator(x[i], y[i], w));
    menInRow[x[i]]++;
    menInColumn[y[i]]++;
  }

  vector<int> maxRow = getMax(menInRow), maxCol = getMax(menInColumn);

  long long total = menInRow[maxRow[0]] + menInColumn[maxCol[0]];
  for (auto &currentRow : maxRow) {
    for (auto &currentCol : maxCol) {
      if (coords.find(pointGenerator(currentRow, currentCol, w)) ==
          coords.end()) {
        printf("%lld\\n", total);
        return 0;
      }
    }
  }
  printf("%lld\\n", total - 1);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

long long pointGenerator(int row, int column, int width) {
  return 1LL * (row * width) + column;
}

vector<int> getMax(vector<int> &men) {
  int maxSize = 0;
  vector<int> ret;
  for (int &i : men)
    maxSize = max(maxSize, i);
  for (int i = 0; i < men.size(); i++) {
    if (maxSize == men[i])
      ret.push_back(i);
  }
  return ret;
}

int main() {

  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);

  vector<int> x(m), y(m);
  vector<long long> coords(m);
  vector<int> menInRow(h, 0);
  vector<int> menInColumn(w, 0);

  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    x[i]--, y[i]--;
    coords[i] = pointGenerator(x[i], y[i], w);
    menInRow[x[i]]++;
    menInColumn[y[i]]++;
  }

  vector<int> maxRow = getMax(menInRow), maxCol = getMax(menInColumn);

  long long total = menInRow[maxRow[0]] + menInColumn[maxCol[0]];
  for (auto &currentRow : maxRow) {
    for (auto &currentCol : maxCol) {
      if (find(coords.begin(), coords.end(),
               pointGenerator(currentRow, currentCol, w)) == coords.end()) {
        printf("%lld\\n", total);
        return 0;
      }
    }
  }
  printf("%lld\\n", total - 1);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> X(W), Y(H);
  map<pair<int, int>, int> G;
  int mx = 0, my = 0;
  int xx, yy;
  vector<int> maxX, maxY;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    G[make_pair(h, w)]++;
    X[w]++;
    if (mx < X[w]) {
      mx = X[w], xx = w;
      maxX.clear();
      maxX.push_back(xx);
    } else if (mx == X[w])
      maxX.push_back(w);
    Y[h]++;
    if (my < Y[h]) {
      my = Y[h], yy = h;
      maxY.clear();
      maxY.push_back(yy);
    } else if (my == Y[h])
      maxY.push_back(h);
  }
  ll res = mx + my;
  bool found = false;
  for (auto x : maxX) {
    for (auto y : maxY) {
      if (G[{y, x}] > 0)
        continue;
      found = true;
      break;
    }
    if (found)
      break;
  }
  if (!found)
    res--;
  cout << res << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> X(W), Y(H);
  vector<vector<bool>> G(H, vector<bool>(W, false));
  int mx = 0, my = 0;
  int xx, yy;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    X[w]++;
    if (mx < X[w])
      mx = X[w], xx = w;
    Y[h]++;
    if (my < Y[h])
      my = Y[h], yy = h;
    G[h][w] = true;
  }
  ll res = mx + my;
  if (G[yy][xx])
    res--;
  cout << res << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N = 3e5 + 2;
int x[N], y[N];
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int n, m, a, b, t;
  set<pair<int, int>> s;
  cin >> n >> m >> t;
  for (int i = 0; i < t; i++) {
    cin >> a >> b;
    s.insert({a, b});
    x[a]++;
    y[b]++;
  }

  int mxx = *max_element(x, x + n + 1);
  int mxy = *max_element(y, y + m + 1);
  vector<int> xx, yy;
  for (int i = 0; i <= max(n, m); i++) {
    if (x[i] == mxx)
      xx.push_back(i);
    if (y[i] == mxy)
      yy.push_back(i);
  }

  for (auto i : xx)
    for (auto j : yy) {

      if (s.find({i, j}) == s.end()) {
        cout << mxx + mxy;
        return 0;
      }
    }

  cout << mxx + mxy - 1;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N = 3e5 + 2;
int x[N], y[N];
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int n, m, a, b, t;
  set<pair<int, int>> s;
  cin >> n >> m >> t;
  for (int i = 0; i < t; i++) {
    cin >> a >> b;
    s.insert({a, b});
    x[a]++;
    y[b]++;
  }

  int mxx = *max_element(x, x + N);
  int mxy = *max_element(y, y + N);
  vector<int> xx, yy;
  for (int i = 0; i < N; i++) {
    if (x[i] == mxx)
      xx.push_back(i);
    if (y[i] == mxy)
      yy.push_back(i);
  }

  int ans = 0;
  for (auto i : xx)
    for (auto j : yy) {
      int tol = 0;
      if (s.find({i, j}) != s.end())
        tol = 1;
      ans = max(ans, mxx + mxy - tol);
    }

  cout << ans;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
template <class T> void printv(vector<T> vec) {
  for (T e : vec)
    cout << e << ' ';
  cout << endl;
}

int main() {
  int h, w, m, a, b;
  cin >> h >> w >> m;
  vector<int> row(h, 0), col(w, 0);
  // vector<vector<int> > target(h, vector<int>(w, 0));
#define pii pair<int, int>
  set<pii> target;
  rep(i, m) {
    cin >> a >> b;
    // target[--a][--b] = 1;
    target.insert(pii(--a, --b));
    row[a]++;
    col[b]++;
  }

  a = *max_element(row.begin(), row.end());
  b = *max_element(col.begin(), col.end());
  vector<int> r, c;
  rep(i, h) if (row[i] == a) r.push_back(i);
  rep(i, w) if (col[i] == b) c.push_back(i);
  for (int i : r)
    for (int j : c) {
      if (target.find(pii(i, j)) == target.end()) {
        cout << a + b << endl;
        return 0;
      }
    }

  cout << a + b - 1 << endl;

  system("pause");
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
template <class T> void printv(vector<T> vec) {
  for (T e : vec)
    cout << e << ' ';
  cout << endl;
}

int main() {
  int h, w, m, a, b;
  cin >> h >> w >> m;
  vector<int> row(h, 0), col(w, 0);
  vector<vector<int>> target(h, vector<int>(w, 0));
  rep(i, m) {
    cin >> a >> b;
    target[--a][--b] = 1;
    row[a]++;
    col[b]++;
  }

  a = *max_element(row.begin(), row.end());
  b = *max_element(col.begin(), col.end());
  vector<int> r, c;
  rep(i, h) if (row[i] == a) r.push_back(i);
  rep(i, w) if (col[i] == b) c.push_back(i);
  for (int i : r)
    for (int j : c) {
      if (!target[i][j]) {
        cout << a + b << endl;
        return 0;
      }
    }

  cout << a + b - 1 << endl;

  system("pause");
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int mh = 0, mw = 0, h, w, m;
  cin >> h >> w >> m;
  vector<int> ch(m), cw(m), bh(h, 0), bw(w, 0);
  for (int i = 0; i < m; ++i) {
    cin >> ch[i] >> cw[i];
    --ch[i];
    --cw[i];
    mh = max(mh, ++bh[ch[i]]);
    mw = max(mw, ++bw[cw[i]]);
  }
  set<int> a, b;
  for (int i = 0; i < m; ++i) {
    if (bh[ch[i]] == mh)
      a.insert(ch[i]);
    if (bw[cw[i]] == mw)
      b.insert(cw[i]);
  }
  int cnt = 0;
  for (int i = 0; i < m; ++i) {
    if (bh[ch[i]] == mh && bw[cw[i]] == mw)
      ++cnt;
    if (cnt == (a.size() * b.size())) {
      cout << mh + mw - 1;
      return 0;
    }
  }
  cout << mh + mw;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int mh = 0, mw = 0, h, w, m;
  cin >> h >> w >> m;
  vector<int> ch(m), cw(m), bh(h, 0), bw(w, 0);
  for (int i = 0; i < m; ++i) {
    cin >> ch[i] >> cw[i];
    --ch[i];
    --cw[i];
    mh = max(mh, ++bh[ch[i]]);
    mw = max(mw, ++bw[cw[i]]);
  }
  set<int> a, b;
  for (int i = 0; i < m; ++i) {
    if (bh[ch[i]] == mh)
      a.insert(ch[i]);
    if (bw[cw[i]] == mw)
      b.insert(cw[i]);
  }
  int cnt = 0;
  for (int i = 0; i < m; ++i) {
    int p = distance(a.begin(), a.find(ch[i]));
    int q = distance(b.begin(), b.find(cw[i]));
    if (p < a.size() && q < b.size())
      ++cnt;
  }
  if (cnt < a.size() * b.size())
    cout << mh + mw;
  else
    cout << mh + mw - 1;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int h, w, m;
  cin >> h >> w >> m;

  vector<int> H(h), W(w);   // 各行、各列に含まれる要素数
  set<pair<int, int>> data; // 爆破対象の配置
  int temp0, temp1;
  int max_h = 0, max_w = 0;
  rep(i, m) {
    cin >> temp0;
    temp0--;
    H[temp0]++;             // 各行の要素数をプラス
    if (H[temp0] > max_h) { // もしその行が最大の要素数ならmax_hにとる
      max_h = H[temp0];
    }
    cin >> temp1;
    temp1--;
    W[temp1]++;             // 各列の要素数をプラス
    if (W[temp1] > max_w) { // もしその行が最大の要素数ならmax_wにとる
      max_w = W[temp1];
    }
    data.insert({temp0, temp1}); // 爆破対象の格納
  }

  vector<int> H_max, W_max;
  for (int i = 0; i < h; i++) { // 行iが最大の要素数ならH_maxに格納
    if (H[i] == max_h)
      H_max.push_back(i);
  }
  for (int i = 0; i < w; i++) { // 列iが最大の要素数ならW_maxに格納
    if (W[i] == max_w)
      W_max.push_back(i);
  }
  // 最大の要素数を持つ行と列の交点に爆破対象がないものを探す
  rep(i, H_max.size()) {
    rep(j, W_max.size()) {
      if (data.count({H_max[i], W_max[j]})) // 交点に爆破対象があれば探索続行
        continue;
      else {
        cout << max_h + max_w << endl; // 交点に爆破対象が無ければ探索終了

        return 0;
      }
    }
  }
  cout << max_h + max_w - 1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int h, w, m;
  cin >> h >> w >> m;

  vector<int> H(h), W(w); // 各行、各列に含まれる要素数
  vector<vector<int>> data(h, vector<int>(w, 0)); // 爆破対象の配置
  int temp0, temp1;
  int max_h = 0, max_w = 0;
  rep(i, m) {
    cin >> temp0;
    temp0--;
    H[temp0]++;             // 各行の要素数をプラス
    if (H[temp0] > max_h) { // もしその行が最大の要素数ならmax_hにとる
      max_h = H[temp0];
    }
    cin >> temp1;
    temp1--;
    W[temp1]++;             // 各列の要素数をプラス
    if (W[temp1] > max_w) { // もしその行が最大の要素数ならmax_wにとる
      max_w = W[temp1];
    }
    data[temp0][temp1] = 1; // 爆破対象の格納
  }

  vector<int> H_max, W_max;
  for (int i = 0; i < h; i++) { // 行iが最大の要素数ならH_maxに格納
    if (H[i] == max_h)
      H_max.push_back(i);
  }
  for (int i = 0; i < w; i++) { // 列iが最大の要素数ならW_maxに格納
    if (W[i] == max_w)
      W_max.push_back(i);
  }
  // 最大の要素数を持つ行と列の交点に爆破対象がないものを探す
  rep(i, H_max.size()) {
    rep(j, W_max.size()) {
      if (data[H_max[i]][W_max[j]] == 1) // 交点に爆破対象があれば探索続行
        continue;
      else {
        cout << max_h + max_w << endl; // 交点に爆破対象が無ければ探索終了

        return 0;
      }
    }
  }
  cout << max_h + max_w - 1 << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

// you should probably see at the bottom ..
#include <bits/stdc++.h>

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(), v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)
#define ff first
#define ss second

using namespace std;

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  map<pair<int, int>, int> val;
  vector<pair<int, int>> row(n + 1), col(m + 1);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    row[a].ff++;
    col[b].ff++;
    val[{a, b}]++;
  }

  for (int i = 1; i <= n; i++)
    row[i].ss = i;
  for (int i = 1; i <= m; i++)
    col[i].ss = i;
  sort(rrange(row)), sort(rrange(col));
  int ans = 0;
  int i = 0, j = 0;
  while (i < n and j < m) {
    int cur = row[i].ff + col[j].ff - val[{row[i].ss, col[j].ss}];
    ans = max(ans, cur);
    int ans1 = 0, ans2 = 0;
    // dbg(i, j,cur);
    if (i + 1 < n)
      ans1 = row[i + 1].ff + col[j].ff - val[{i + 1, j}];
    if (j + 1 < m)
      ans2 = row[i].ff + col[j + 1].ff - val[{i, j + 1}];
    if (cur > max(ans1, ans2))
      break;
    else if (ans1 >= ans2)
      i++;
    else
      j++;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
  int t_c = 1;
  //	cin >> t_c;
  while (t_c--)
    solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
 */


Error: 0

Fixed submission:

// you should probably see at the bottom ..
#include <bits/stdc++.h>

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(), v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(1e3 + 10)

using namespace std;

int grid[N][N] = {};
int pref[N][N] = {};

void solve() {
  int h, w, m;
  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    grid[a][b] = 1;
  }

  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      pref[i][j] =
          pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j];

  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int cur = pref[h][j] - pref[h][j - 1] + pref[i][w] - pref[i - 1][w] -
                grid[i][j];
      // dbg(i, j, cur);
      ans = max(cur, ans);
    }
  }

  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
  int t_c = 1;
  //	cin >> t_c;
  while (t_c--)
    solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
 */