alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int comp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}

int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  vector<pair<int, int>> r(h);
  vector<pair<int, int>> c(w);
  map<pair<int, int>, int> a;
  for (int i = 0; i < h; i++)
    r[i].second = i;
  for (int i = 0; i < w; i++)
    c[i].second = i;
  for (int i = 0; i < m; i++) {
    int R, C;
    cin >> R >> C;
    R--;
    C--;
    r[R].first++;
    c[C].first++;
    a[{R, C}] = 1;
  }
  sort(r.begin(), r.end(), comp);
  sort(c.begin(), c.end(), comp);
  if (a[{r[0].second, c[0].second}] == 0) {
    cout << r[0].first + c[0].first << endl;
  } else {
    int temp = r[0].first + c[0].first - a[{r[0].second, c[0].second}];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int t = r[i].first + c[j].first - a[{r[i].second, c[j].second}];
        if (t > temp) {
          cout << t << endl;
          return 0;
        }
        if (c[j].first < (c[0].first))
          break;
      }
      if (r[i].first < (r[0].first))
        break;
    }
    cout << temp << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int comp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}

int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  vector<pair<int, int>> r(h);
  vector<pair<int, int>> c(w);
  map<pair<int, int>, int> a;
  for (int i = 0; i < h; i++)
    r[i].second = i;
  for (int i = 0; i < w; i++)
    c[i].second = i;
  for (int i = 0; i < m; i++) {
    int R, C;
    cin >> R >> C;
    R--;
    C--;
    r[R].first++;
    c[C].first++;
    a[{R, C}] = 1;
  }
  sort(r.begin(), r.end(), comp);
  sort(c.begin(), c.end(), comp);
  if (a[{r[0].second, c[0].second}] == 0) {
    cout << r[0].first + c[0].first << endl;
  } else {
    int temp = r[0].first + c[0].first - a[{r[0].second, c[0].second}];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int t = r[i].first + c[j].first - a[{r[i].second, c[j].second}];
        if (t > temp) {
          cout << t << endl;
          return 0;
        }
        if (c[j].first < (c[0].first - 1))
          break;
      }
      if (r[i].first < (r[0].first - 1))
        break;
    }
    cout << temp << endl;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> hw(M);
  vector<int> yoko(H), tate(W);
  for (int i = 0; i < M; i++) {
    cin >> hw[i].first >> hw[i].second;
    hw[i].first--;
    hw[i].second--;
    yoko[hw[i].first]++;
    tate[hw[i].second]++;
  }
  int yokoM = 0, tateM = 0;
  set<int> yokos, tates;
  for (int i = 0; i < H; i++) {
    if (yoko[i] > yokoM) {
      yokoM = yoko[i];
      while (!yokos.empty())
        yokos.erase(yokos.begin(), yokos.end());
      yokos.insert(i);
    } else if (yoko[i] == yokoM)
      yokos.insert(i);
  }
  for (int i = 0; i < W; i++) {
    if (tate[i] > tateM) {
      tateM = tate[i];
      while (!tates.empty())
        tates.erase(tates.begin(), tates.end());
      tates.insert(i);
    } else if (tate[i] == tateM)
      tates.insert(i);
  }
  int ans = yokoM + tateM;
  int judge = 0;
  for (int i = 0; i < M; i++) {
    if (yokos.count(hw[i].first) && tates.count(hw[i].second))
      judge++;
  }
  if (judge == yokos.size() * tates.size())
    ans--;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> hw(M);
  vector<vector<int>> mapping(H, vector<int>(W));
  for (int i = 0; i < M; i++) {
    cin >> hw[i].first >> hw[i].second;
    hw[i].first--;
    hw[i].second--;
    mapping[hw[i].first][hw[i].second] = 1;
  }
  vector<int> yoko(H), tate(W);
  for (int i = 0; i < H; i++) {
    int cnt = 0;
    for (int j = 0; j < W; j++) {
      if (mapping[i][j] == 1)
        cnt++;
    }
    yoko[i] = cnt;
  }
  for (int i = 0; i < W; i++) {
    int cnt = 0;
    for (int j = 0; j < H; j++) {
      if (mapping[j][i] == 1)
        cnt++;
    }
    tate[i] = cnt;
  }
  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int sum = yoko[i] + tate[j];
      if (mapping[i][j] == 1)
        sum--;
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

  vector<int> hPl(H, 0);
  vector<int> wPl(W, 0);
  set<pii> st;

  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;

    hPl[h]++;
    wPl[w]++;
    st.insert({h, w});
  }

  int hmax = *max_element(hPl.begin(), hPl.end());
  int wmax = *max_element(wPl.begin(), wPl.end());

  vector<int> hmaxId, wmaxId;

  for (int i = 0; i < H; i++) {
    if (hPl[i] == hmax) {
      hmaxId.push_back(i);
    }
  }

  for (int i = 0; i < W; i++) {
    if (wPl[i] == wmax) {
      wmaxId.push_back(i);
    }
  }

  bool bombOverlap = true;

  int ans = hmax + wmax;
  for (auto hid : hmaxId) {
    for (auto wid : wmaxId) {
      if (st.find({hid, wid}) == st.end()) {
        bombOverlap = false;
        cout << ans << endl;
        return 0;
      }
    }
  }

  ans -= 1;

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

  vector<int> hPl(H, 0);
  vector<int> wPl(W, 0);
  map<pii, bool> m;

  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;

    hPl[h]++;
    wPl[w]++;
    m[{h, w}] = true;
  }

  int ans = 0;

  int hmax = *max_element(hPl.begin(), hPl.end());
  int wmax = *max_element(wPl.begin(), wPl.end());

  vector<int> hmaxId, wmaxId;

  for (int i = 0; i < H; i++) {
    if (hPl[i] == hmax) {
      hmaxId.push_back(i);
    }
  }

  for (int i = 0; i < W; i++) {
    if (wPl[i] == wmax) {
      wmaxId.push_back(i);
    }
  }

  bool bombOverlap = true;
  for (auto hid : hmaxId) {
    for (auto wid : wmaxId) {
      if (!m.count(pii(hid, wid))) {
        bombOverlap = false;
      }
    }
  }

  if (bombOverlap) {
    ans = hmax + wmax - 1;
  } else {
    ans = hmax + wmax;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define pb push_back
#define wrln cout << '\\n';
#define fi first
#define se second
using namespace std;
const int N = 3e5 + 10;
int di[N], dj[N], n, m, sl, k, y, x, i, j, res, dimax, djmax, disum, djsum, sum;
vector<pair<int, int>> luu;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> sl;
  x = y = 0;
  while (sl--) {
    cin >> i >> j;
    di[i]++;
    dj[j]++;
    dimax = max(di[i], dimax);
    djmax = max(dj[j], djmax);
    luu.pb({i, j});
  }
  for (int i = 1; i <= n; i++)
    if (di[i] == dimax)
      disum++;
  for (int i = 1; i <= m; i++)
    if (dj[i] == djmax)
      djsum++;
  sum += disum * djsum;
  for (auto i : luu) {
    if (di[i.fi] == dimax && djmax == dj[i.se])
      sum--;
    //  cout<<di[i.fi]<<" "<<dj[i.se]<<" "<<i.fi<<" "<<i.se; wrln;
  }
  //   cout<<sum; wrln;
  cout << dimax + djmax - (sum == 0);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define wrln cout << '\\n';
using namespace std;
const int N = 1e5 + 10;
map<pair<int, int>, bool> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, sl, k, y, x, i, j;
  int di[N], dj[N];
  cin >> n >> m >> sl;
  x = y = 1;
  while (sl--) {
    cin >> i >> j;
    di[i]++;
    dj[j]++;
    mp[{i, j}] = 1;
    if (di[i] > di[x])
      x = i;
    if (dj[j] > dj[y])
      y = j;
    if (mp.find({x, y}) != mp.end())
      k = 1;
    else
      k = 0;
  }
  cout << di[x] + dj[y] - k;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int nm = 3e5;
int h, w, m, a[nm], b[nm], ans = 0, mx = 0, my = 0;
vector<int> xs, ys;
vector<P> c;

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

  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    ++a[x];
    ++b[y];
    c.emplace_back(x, y);
  }

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

  for (int i = 0; i < h; ++i) {
    if (mx == a[i])
      xs.emplace_back(i);
    else if (a[i] > mx) {
      mx = a[i];
      xs.clear();
      xs.emplace_back(i);
    }
  }
  for (int i = 0; i < w; ++i) {
    if (my == b[i])
      ys.emplace_back(i);
    else if (b[i] > my) {
      my = b[i];
      ys.clear();
      ys.emplace_back(i);
    }
  }

  for (int i : xs)
    for (int j : ys) {
      if (!binary_search(c.begin(), c.end(), make_pair(i, j))) {
        cout << mx + my << endl;
        return 0;
      }
    }

  cout << mx + my - 1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int nm = 3e5;
int h, w, m, a[nm], b[nm], ans = 0;
vector<P> c;

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

  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    ++a[x];
    ++b[y];
    c.emplace_back(x, y);
  }

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

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, a[i] + b[j] -
                         binary_search(c.begin(), c.end(), make_pair(i, j)));
    }
  }

  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++)
int64_t MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> LH(H, 0), LW(W, 0);
  set<pair<int, int>> B;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    B.insert(make_pair(a, b));
    LH.at(a)++;
    LW.at(b)++;
  }
  int HM = 0, WM = 0;
  vector<int> HH, WW;
  rep(i, H) {
    if (HM < LH.at(i)) {
      HH = {};
      HH.push_back(i);
      HM = LH.at(i);
    } else if (HM == LH.at(i)) {
      HH.push_back(i);
    }
  }
  rep(i, W) {
    if (WM < LW.at(i)) {
      WW = {};
      WW.push_back(i);
      WM = LW.at(i);
    } else if (WM == LW.at(i)) {
      WW.push_back(i);
    }
  }
  int s = HH.size(), t = WW.size(), ans = WM + HM;
  bool c = false, finish = false;
  rep(i, s) {
    rep(j, t) {
      pair<int, int> k = make_pair(HH.at(i), WW.at(j));
      if (B.count(k) == false) {
        c = true;
        finish = true;
        break;
      }
    }
    if (finish)
      break;
  }

  if (c)
    cout << ans;
  else
    cout << ans - 1;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> LH(H, 0), LW(W, 0);
  vector<vector<bool>> B(H, vector<bool>(W, false));
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    B.at(a).at(b) = true;
    LH.at(a)++;
    LW.at(b)++;
  }
  int HM = 0, WM = 0;
  vector<int> HH, WW;
  rep(i, H) {
    if (HM < LH.at(i)) {
      HH = {};
      HH.push_back(i);
      HM = LH.at(i);
    } else if (HM == LH.at(i)) {
      HH.push_back(i);
    }
  }
  rep(i, W) {
    if (WM < LW.at(i)) {
      WW = {};
      WW.push_back(i);
      WM = LW.at(i);
    } else if (WM == LW.at(i)) {
      WW.push_back(i);
    }
  }
  int s = HH.size(), t = WW.size(), ans = WM + HM;
  bool c = false, finish = false;
  rep(i, s) {
    rep(j, t) {
      if (B.at(HH.at(i)).at(WW.at(j)) == false) {
        c = true;
        finish = true;
        break;
      }
    }
    if (finish)
      break;
  }

  if (c)
    cout << ans;
  else
    cout << ans - 1;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;

void solve(long long H, long long W, long long M, std::vector<long long> h,
           std::vector<long long> w) {
  map<ll, ll> Mh;
  map<ll, ll> Mw;
  using pll = pair<ll, ll>;
  set<pll> S;
  for (ll i = 0; i < M; ++i) {
    Mh[h[i]]++;
    Mw[w[i]]++;
    S.insert({h[i], w[i]});
  }
  const auto cmp = [](pll lhs, pll rhs) { return lhs.second < rhs.second; };
  auto mh = *max_element(Mh.begin(), Mh.end(), cmp);
  auto mw = *max_element(Mw.begin(), Mw.end(), cmp);

  set<ll> hs;
  for (auto mhi : Mh) {
    if (mhi.second == mh.second) {
      hs.insert(mhi.first);
    }
  }
  set<ll> ws;
  for (auto mwi : Mw) {
    if (mwi.second == mw.second) {
      ws.insert(mwi.first);
    }
  }

  ll rv = mh.second + mw.second - 1;
  for (auto h : hs) {
    for (auto w : ws) {
      if (S.count({h, w}) == 0) {
        rv++;
        goto eos;
      }
    }
  }

eos:
  cout << rv << endl;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> h(M);
  std::vector<long long> w(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &h[i]);
    scanf("%lld", &w[i]);
  }
  solve(H, W, M, std::move(h), std::move(w));
  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

void solve(long long H, long long W, long long M, std::vector<long long> h,
           std::vector<long long> w) {
  map<ll, ll> Mh;
  map<ll, ll> Mw;
  using pll = pair<ll, ll>;
  set<pll> S;
  for (ll i = 0; i < M; ++i) {
    Mh[h[i]]++;
    Mw[w[i]]++;
    S.insert({h[i], w[i]});
  }
  const auto cmp = [](pll lhs, pll rhs) { return lhs.second < rhs.second; };
  auto mh = *max_element(Mh.begin(), Mh.end(), cmp);
  auto mw = *max_element(Mw.begin(), Mw.end(), cmp);

  set<ll> hs;
  for (auto mhi : Mh) {
    if (mhi.second >= mh.second - 1) {
      hs.insert(mhi.first);
    }
  }
  set<ll> ws;
  for (auto mwi : Mw) {
    if (mwi.second >= mw.second - 1) {
      ws.insert(mwi.first);
    }
  }

  ll rv = 0;
  for (auto h : hs) {
    for (auto w : ws) {
      rv = max(Mh[h] + Mw[w] - (ll)S.count({h, w}), rv);
    }
  }
  cout << rv << endl;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> h(M);
  std::vector<long long> w(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &h[i]);
    scanf("%lld", &w[i]);
  }
  solve(H, W, M, std::move(h), std::move(w));
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

map<long long int, long long int> m3[300001];
int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  long long int n, m, k;
  cin >> n >> m >> k;
  map<long long int, long long int> m1;
  map<long long int, long long int> m2;

  long long int maxia = INT_MIN;
  long long int maxib = INT_MIN;
  while (k--) {
    long long int a, b;
    cin >> a >> b;
    m1[a]++;
    m2[b]++;
    m3[a][b] = 1;
    if (maxia < m1[a])
      maxia = m1[a];
    if (maxib < m2[b])
      maxib = m2[b];
  }

  vector<long long int> left;
  vector<long long int> right;
  for (auto i = m1.begin(); i != m1.end(); i++) {
    if (i->second == maxia) {
      left.push_back(i->first);
    }
  }

  for (auto i = m2.begin(); i != m2.end(); i++) {
    if (i->second == maxib) {
      right.push_back(i->first);
    }
  }

  long long int ans = 0;
  long long int c1 = 0;
  for (long long int i = 0; i < left.size(); i++) {
    for (long long int j = 0; j < right.size(); j++) {
      c1++;
      ans = max(ans, maxia + maxib - m3[left[i]][right[j]]);
      if (c1 > n)
        break;
    }
    if (c1 > n)
      break;
  }
  cout << ans << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  long long int n, m, k;
  cin >> n >> m >> k;
  long long int arr[n][m];
  memset(arr, 0, sizeof(arr));
  while (k--) {
    long long int a, b;
    cin >> a >> b;
    arr[a - 1][b - 1] = 1;
  }
  long long int brr[n];
  long long int crr[n];
  for (long long int i = 0; i < n; i++) {
    long long int tp = 0;
    for (long long int j = 0; j < m; j++) {
      if (arr[i][j] == 1)
        tp++;
    }
    brr[i] = tp;
  }
  for (long long int i = 0; i < m; i++) {
    long long int tp = 0;
    for (long long int j = 0; j < n; j++) {
      if (arr[j][i] == 1)
        tp++;
    }
    crr[i] = tp;
  }
  long long int maxi = INT_MIN;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (brr[i] + crr[j] > maxi) {
        maxi = brr[i] + crr[j];
        if (arr[i][j] == 1)
          maxi--;
      }
    }
  }

  cout << maxi << endl;

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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int h, w, m, tmph, tmpw, ans;
  cin >> h >> w >> m;
  vector<vector<int>> bh(h, vector<int>(2)), bw(w, vector<int>(2));
  vector<pair<int, int>> b;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &tmph, &tmpw);
    tmph--;
    tmpw--;
    bh[tmph][0]++;
    bw[tmpw][0]++;
    b.push_back(make_pair(tmph, tmpw));
  }
  for (int i = 0; i < h; i++) {
    bh[i][1] = i;
  }
  for (int j = 0; j < w; j++) {
    bw[j][1] = j;
  }
  sort(bh.begin(), bh.end());
  reverse(bh.begin(), bh.end());
  sort(bw.begin(), bw.end());
  reverse(bw.begin(), bw.end());
  sort(b.begin(), b.end());
  int i = 0, j;
  while (i < h && bh[i][0] == bh[0][0]) {
    j = 0;
    while (j < w && bw[j][0] == bw[0][0]) {
      auto itr = lower_bound(b.begin(), b.end(), make_pair(bh[i][1], bw[j][1]));
      if (*itr != make_pair(bh[i][1], bw[j][1])) {
        ans = bh[i][0] + bw[j][0];
        i = h;
        break;
      } else {
        ans = bh[i][0] + bw[j][0] - 1;
      }
      j++;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int h, w, m, tmph, tmpw, ans = 0, k;
  cin >> h >> w >> m;
  vector<int> bh(h, 0), bw(w, 0);
  vector<pair<int, int>> b;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &tmph, &tmpw);
    tmph--;
    tmpw--;
    bh[tmph]++;
    bw[tmpw]++;
    b.push_back(make_pair(tmph, tmpw));
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      auto itr = lower_bound(b.begin(), b.end(), make_pair(i, j));
      k = bh[i] + bw[j] - (*itr == make_pair(i, j) ? 1 : 0);
      if (k > ans)
        ans = k;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int h_num[300100];
int w_num[300100];

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

  set<pair<int, int>> s;
  for (int h = 0; h < H; ++h) {
    h_num[h] = 0;
  }

  for (int w = 0; w < W; ++w) {
    w_num[w] = 0;
  }

  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;

    h_num[h]++;
    w_num[w]++;
    s.emplace(h, w);
  }

  int h_max = 0;
  int h_index = -1;
  int w_max = 0;
  int w_index = -1;

  set<int> w_idx_candidate;
  set<int> h_idx_candidate;

  for (int h = 0; h < H; ++h) {
    if (h_max < h_num[h]) {
      h_max = h_num[h];
      h_index = h;
      h_idx_candidate.clear();
      h_idx_candidate.insert(h_index);
    } else if (h_max == h_num[h]) {
      h_idx_candidate.insert(h);
    }
  }

  for (int w = 0; w < W; ++w) {
    if (w_max < w_num[w]) {
      w_max = w_num[w];
      w_index = w;
      w_idx_candidate.clear();
      w_idx_candidate.insert(w);
    } else if (w_max == w_num[w]) {
      w_idx_candidate.insert(w);
    }
  }

  bool flag = false;
  if (h_max > w_max) {
    for (int w_idx : w_idx_candidate) {
      if (s.count({h_index, w_idx}) == 0) {
        flag = true;
      }
    }
  } else {
    for (int h_idx : h_idx_candidate) {
      if (s.count({h_idx, w_index}) == 0) {
        flag = true;
      }
    }
  }

  int ans = h_max + w_max;
  if (flag == false) {
    ans -= 1;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

// field[30010][30010]
bool field[10][10];

int h_num[10];
int w_num[10];

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

  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;

    h_num[h]++;
    w_num[w]++;
    field[h][w] = true;
  }

  int h_max = 0;
  int h_index = -1;
  int w_max = 0;
  int w_index = -1;

  for (int h = 0; h < H; ++h) {
    if (h_max < h_num[h])
      h_max = h_num[h];
    h_index = h;
  }

  for (int w = 0; w < W; ++w) {
    if (w_max < w_num[w])
      w_max = w_num[w];
    w_index = w;
  }

  int ans = h_max + w_max;
  if (field[h_index][w_index] == true) {
    ans--;
  }

  cout << ans << endl;
}