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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int main() {
  fastio int n, t, i, j, x, k = 0, y;
  int h, w, ans;
  cin >> h >> w >> n;

  set<pair<int, int>> st;
  vector<int> a(h + 1, 0), b(w + 1, 0);

  for (i = 0; i < n; i++) {
    cin >> x >> y;
    st.insert({x, y});
    a[x]++, b[y]++;
  }

  vector<pair<int, int>> l(h), p(w);

  for (i = 1; i <= h; i++)
    l[i - 1] = {a[i], i};

  for (i = 1; i <= w; i++)
    p[i - 1] = {b[i], i};

  sort(l.rbegin(), l.rend());
  sort(p.rbegin(), p.rend());

  ans = l[0].first + p[0].first;
  if (st.count({l[0].second, p[0].second}) == 1)
    ans -= 1;
  else {
    cout << ans;
    exit(0);
  }

  i = 1, j = 1;
  x = l[0].first;
  y = p[0].first;
  int c = 0;

  if (i < h) {
    while (l[i].first == x) {
      if (st.count({l[i].second, p[0].second}) == 0) {
        c = 1;
        ans++;
      }
      i++;
      if (i == h || c == 1)
        break;
    }
  }
  if (j < w && c == 0) {
    while (p[j].first == y) {
      if (st.count({l[0].second, p[j].second}) == 0) {
        c = 1;
        ans++;
      }
      j++;
      if (j == w || c == 1)
        break;
    }
  }
  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int main() {
  fastio int n, t, i, j, x, k = 0, y;
  int h, w, ans;
  cin >> h >> w >> n;

  vector<vector<int>> v(h + 2, vector<int>(w + 2, 0));
  vector<int> a(h + 1, 0), b(w + 1, 0);

  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v[x][y]++;
    a[x]++, b[y]++;
  }

  vector<pair<int, int>> l(h), p(w);

  for (i = 1; i <= h; i++)
    l[i - 1] = {a[i], i};

  for (i = 1; i <= w; i++)
    p[i - 1] = {b[i], i};

  sort(l.rbegin(), l.rend());
  sort(p.rbegin(), p.rend());

  ans = l[0].first + p[0].first;
  if (v[l[0].second][p[0].second] != 0)
    ans -= 1;
  else {
    cout << ans;
    k = -1;
  }

  if (k != -1) {
    i = 1, j = 1;
    x = l[0].first;
    y = p[0].first;
    int c = 0;

    if (i < h) {
      while (l[i].first == x) {
        if (v[l[i].second][p[0].second] == 0) {
          c = 1;
          ans++;
        }
        i++;
        if (i == h || c == 1)
          break;
      }
    }
    if (j < w && c == 0) {
      while (p[j].first == y) {
        if (v[l[0].second][p[j].second] == 0) {
          c = 1;
          ans++;
        }
        j++;
        if (j == w || c == 1)
          break;
      }
    }
    cout << ans;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define print(x) cout << x << endl
#define prints(x) cout << x << " "
#define printline cout << endl

bool comp(const pair<ll, ll> a, const pair<ll, ll> b) {
  return a.second > b.second;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  ll h, w, m;
  cin >> h >> w >> m;
  set<pair<ll, ll>> s;
  vector<ll> H(3e5, 0);
  vector<ll> W(3e5, 0);
  for (ll i = 0; i < m; i++) {
    ll r, c;
    cin >> r >> c;
    r--;
    c--;
    H[r]++;
    W[c]++;
    s.insert({r, c});
  }

  ll ans = 0;
  vector<pair<ll, ll>> hp;
  vector<pair<ll, ll>> wp;
  for (ll i = 0; i < 3e5; i++) {
    if (H[i])
      hp.push_back({i, H[i]});
    if (W[i])
      wp.push_back({i, W[i]});
  }
  sort(hp.begin(), hp.end(), comp);
  sort(wp.begin(), wp.end(), comp);
  // for (ll i = 0; i < hp.size(); i++)
  // {
  //     prints(hp[i].second);
  // }printline;
  // for (ll i = 0; i < wp.size(); i++)
  // {
  //     prints(wp[i].second);
  // }printline;
  ll mh = hp[0].second;
  ll mw = wp[0].second;
  ans = mh + mw - 1;
  for (ll i = 0; i < (ll)hp.size(); i++) {
    if (hp[i].second != mh)
      break;
    int found = 0;
    for (ll j = 0; j < (ll)wp.size(); j++) {
      if (wp[j].second != mw)
        break;
      ll temp = hp[i].second + wp[j].second;
      if (s.find({hp[i].first, wp[j].first}) != s.end()) {
        temp--;
      } else {
        ans++;
        found = 1;
        break;
      }

      ans = max(ans, temp);
    }
    if (found)
      break;
  }
  print(ans);
  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long
#define print(x) cout << x << endl
#define prints(x) cout << x << " "
#define printline cout << endl

bool comp(const pair<ll, ll> a, const pair<ll, ll> b) {
  return a.second > b.second;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  ll h, w, m;
  cin >> h >> w >> m;
  set<pair<ll, ll>> s;
  vector<ll> H(3e5, 0);
  vector<ll> W(3e5, 0);
  for (ll i = 0; i < m; i++) {
    ll r, c;
    cin >> r >> c;
    r--;
    c--;
    H[r]++;
    W[c]++;
    s.insert({r, c});
  }

  ll ans = 0;
  vector<pair<ll, ll>> hp;
  vector<pair<ll, ll>> wp;
  for (ll i = 0; i < 3e5; i++) {
    if (H[i])
      hp.push_back({i, H[i]});
    if (W[i])
      wp.push_back({i, W[i]});
  }
  sort(hp.begin(), hp.end(), comp);
  sort(wp.begin(), wp.end(), comp);
  // for (ll i = 0; i < hp.size(); i++)
  // {
  //     prints(hp[i].second);
  // }printline;
  // for (ll i = 0; i < wp.size(); i++)
  // {
  //     prints(wp[i].second);
  // }printline;
  ll mh = hp[0].second;
  ll mw = wp[0].second;
  ans = mh + mw - 1;
  for (ll i = 0; i < (ll)hp.size(); i++) {
    if (hp[i].second != mh)
      break;
    for (ll j = 0; j < (ll)wp.size(); j++) {
      if (wp[j].second != mw)
        break;
      ll temp = hp[i].second + wp[j].second;
      if (s.find({hp[i].first, wp[j].first}) != s.end())
        temp--;
      ans = max(ans, temp);
    }
  }
  print(ans);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {

  int h, w, m;
  cin >> h >> w >> m;

  set<P> s; // setのfindの計算量はlog
  mp x, y;
  int hmval = 0, wmval = 0;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    s.insert(P{a, b});
    x[a]++;
    y[b]++;
    chmax(hmval, x[a]);
    chmax(wmval, y[b]);
  }

  int ans = hmval + wmval - 1; // 爆弾が重複しているとしてマイナス1
  // 各行列ごとに、最大値と一致するhとwを答えの候補とする
  vector<int> hmax, wmax;
  for (auto q : x) {
    if (hmval == q.second) {
      hmax.push_back(q.first);
    }
  }
  for (auto q : y) {
    if (wmval == q.second) {
      wmax.push_back(q.first);
    }
  }

  // 答えの候補の中に重複しない（爆弾が存在しない）座標があれば、それが最大値となるからans+1をする
  for (auto q : hmax) {
    for (auto p : wmax) {
      if (s.find(P{q, p}) == s.end()) {
        cout << ans + 1 << "\\n";
        return 0;
      }
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {

  int h, w, m;
  cin >> h >> w >> m;

  vector<P> a(m);
  mp x, y;
  int hmval = 0, wmval = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a[i].first >> a[i].second;
    x[a[i].first]++;
    y[a[i].second]++;
    chmax(hmval, x[a[i].first]);
    chmax(wmval, y[a[i].second]);
  }

  int ans = hmval + wmval - 1; // 爆弾が重複しているとしてマイナス1
  // 各行列ごとに、最大値と一致するhとwを答えの候補とする
  vector<int> hmax, wmax;
  for (auto q : x) {
    if (hmval == q.second) {
      hmax.push_back(q.first);
    }
  }
  for (auto q : y) {
    if (wmval == q.second) {
      wmax.push_back(q.first);
    }
  }

  // 答えの候補の中に重複しない（爆弾が存在しない）座標があれば、それが最大値となるからans+1をする
  for (auto q : hmax) {
    for (auto p : wmax) {
      if (find(all(a), P{q, p}) == a.end()) {
        cout << ans + 1 << "\\n";
        return 0;
      }
    }
  }

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

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define pb push_back
#define int long long
#define ld long double

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> cnt(n), cnt1(m);
  set<int> st;
  set<pair<int, int>> lol;
  vector<vector<int>> go(n);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    go[a].pb(b);
    st.insert(a);
    cnt[a]++, cnt1[b]++;
  }
  for (int i = 0; i < m; i++) {
    if (cnt1[i] != 0) {
      lol.insert({cnt1[i], i});
    }
  }
  int anss = 0;
  for (auto to : st) {
    int ans = 0;
    for (auto t : go[to]) {
      lol.erase({cnt1[t], t});
      ans = max(ans, cnt1[t] - 1);
    }
    if (!lol.empty()) {
      ans = max(ans, lol.rbegin()->first);
    }
    anss = max(anss, cnt[to] + ans);
    for (auto t : go[to]) {
      lol.insert({cnt1[t], t});
    }
  }
  cout << anss << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define pb push_back
#define int long long
#define ld long double

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> cnt(n), cnt1(m);
  vector<vector<int>> v(n, vector<int>(m));
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v[a][b] = 1;
    cnt[a]++, cnt1[b]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, cnt[i] + cnt1[j] - v[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define endl '\\n'
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

// Most important thing in CP - Have Fun :)

void solve() {
  // write here
  int h, w, m;
  cin >> h >> w >> m;
  unordered_map<int, int> xs;
  unordered_map<int, int> ys;
  map<pair<int, int>, int> pt;
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    xs[x]++;
    ys[y]++;
    pt[{x, y}] = 1;
  }
  int xval = 0, yval = 0;
  int xco, yco;
  vector<int> contx, conty;
  for (auto &it : xs) {
    if (xval < it.second) {
      xval = it.second;
      contx.clear();
      contx.pb(it.first);
    } else if (xval == it.second) {
      contx.pb(it.first);
    }
  }
  for (auto &it : ys) {
    if (yval < it.second) {
      yval = it.second;
      conty.clear();
      conty.pb(it.first);
    } else if (yval == it.second) {
      conty.pb(it.first);
    }
  }
  // cout<<xco<<" "<<yco<<endl;
  // rep(i,0,sz(conty))cout<<conty[i]<<" ";
  int ans = xval + yval - 1;
  int ok = 0;
  for (int i = 0; i < sz(contx); i++) {
    for (int j = 0; j < sz(conty); j++) {
      if (pt.count({contx[i], conty[j]}) == 0) {
        ans++;
        cout << ans << endl;
        return;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  // insert code
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define endl '\\n'
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

// Most important thing in CP - Have Fun :)

void solve() {
  // write here
  int h, w, m;
  cin >> h >> w >> m;
  unordered_map<int, int> xs;
  unordered_map<int, int> ys;
  map<pair<int, int>, int> pt;
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    xs[x]++;
    ys[y]++;
    pt[{x, y}] = i;
  }
  ll ans = 0;
  ll mxval = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      ans += xs[i];
      ans += ys[j];
      if (pt.count({i, j}))
        ans--;
      mxval = max(ans, mxval);
      ans = 0;
    }
  }
  cout << mxval << endl;
  return;
}

int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  // insert code
  solve();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using PV = pair<int, vector<int>>;

using PII = pair<int, int>;

void show(vector<int> &v) {
  for (auto x : v) {
    printf("%d ", x);
  }
  printf("\\n");
}

PV calc(vector<int> v) {
  int maxi = 0;
  vector<int> nums;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > maxi) {
      maxi = v[i];
      nums = {i};
    } else if (v[i] == maxi) {
      nums.emplace_back(i);
    }
  }

  // printf("maxi %d: nums ", maxi);
  // for (auto x: nums) {
  // 	printf("%d ", x);
  // }
  // printf("\\n");
  return PV(maxi, nums);
}

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

  set<PII> bombs;
  vector<int> bomb_row(h, 0), bomb_col(w, 0);
  int row, col;
  for (int i = 0; i < m; i++) {
    cin >> row >> col;
    row--;
    col--;
    bombs.emplace(row, col);
    bomb_row[row]++;
    bomb_col[col]++;
  }

  // show(bomb_row);
  // show(bomb_col);

  auto ret_r = calc(bomb_row);
  auto ret_c = calc(bomb_col);

  int ans = ret_r.first + ret_c.first - 1;
  for (auto r : ret_r.second) {
    for (auto c : ret_c.second) {
      if (bombs.count(make_pair(r, c)) == 0) {
        ans++;
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using PV = pair<int, vector<int>>;

PV calc(vector<int> v) {
  int maxi = 0;
  vector<int> nums;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > maxi) {
      maxi = v[i];
      nums = {i};
    } else if (v[i] == maxi) {
      nums.emplace_back(v[i]);
    }
  }

  return PV(maxi, nums);
}

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

  vector<int> bomb_row(h, 0), bomb_col(w, 0);
  int row, col;
  for (int i = 0; i < m; i++) {
    cin >> row >> col;
    bomb_row[row]++;
    bomb_col[col]++;
  }

  auto r = calc(bomb_row);
  auto c = calc(bomb_col);

  int ans = r.first + c.first;
  if (r.second.size() == 1 && c.second.size() == 1 &&
      r.second[0] == c.second[0]) {
    ans--;
  }

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

#include <bits/stdc++.h>
#define N 300001
using namespace std;
int n, mxx, mxy, sx[N], sy[N];
vector<int> gx, gy;
map<pair<int, int>, char> mp;
int main(void) {
  int i, x, y;
  scanf("%d%d%d", &x, &y, &n);
  while (n--)
    scanf("%d%d", &x, &y), mxx = max(mxx, ++sx[x]), mxy = max(mxy, ++sy[y]),
                           mp[make_pair(x, y)] = 1;
  for (i = 1; i <= 300000; ++i)
    if (sx[i] == mxx)
      gx.push_back(i);
  for (i = 1; i <= 300000; ++i)
    if (sy[i] == mxy)
      gy.push_back(i);
  for (int x : gx)
    for (int y : gy)
      if (!mp.count(make_pair(x, y)))
        return printf("%d\\n", mxx + mxy), 0; // 至少一对不重合
  printf("%d\\n", mxx + mxy - 1);             // 都必定重叠
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 3e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int h1, w1, m, bm, cm, bsum = 0, csum = 0;
int a[MAX], b[MAX], c[MAX];

void solve() {
  cin >> h1 >> w1 >> m;
  // map<int,int>a;
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  memset(c, 0, sizeof(c));
  for (int i = 0; i < m; ++i) {
    int h, w;
    cin >> h >> w;
    a[h * w] = 1;
    // a[h]=w;
    b[h]++;
    c[w]++;
    if (b[h] > bsum)
      bsum = b[h], bm = h;
    if (c[w] > csum)
      csum = c[w], cm = w;
  }
  cout << (a[bm * cm] ? bsum + csum - 1 : bsum + csum);
}

int main() {
  int _ = 1;
  //    cin >> _;
  while (_--) {
    solve();
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

int hcnt[300005] = {};
int wcnt[300005] = {};
vector<int> hp, wp;

map<pair<int, int>, int> coors;

int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  int hm = 0, wm = 0;
  for (int i = 0; i < m; ++i) {
    int hh, ww;
    scanf("%d%d", &hh, &ww);

    hm = max(++hcnt[hh], hm);
    wm = max(++wcnt[ww], wm);
    coors.insert({{hh, ww}, 0});
  }

  for (int i = 1; i <= h; ++i) {
    if (hm == hcnt[i])
      hp.push_back(i);
  }

  for (int j = 1; j <= w; ++j) {
    if (wm == wcnt[j])
      wp.push_back(j);
  }
  int ans = 0;
  for (int i : hp) {
    for (int j : wp) {
      ans = max(ans, hm + wm - (coors.count({i, j}) ? 1 : 0));
      if (ans == hm + wm)
        break;
    }
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

int hcnt[300005] = {};
int wcnt[300005] = {};
vector<int> hp, wp;

map<pair<int, int>, int> coors;

int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  int hm = 0, wm = 0;
  for (int i = 0; i < m; ++i) {
    int hh, ww;
    scanf("%d%d", &hh, &ww);

    hm = max(++hcnt[hh], hm);
    wm = max(++wcnt[ww], wm);
    coors.insert({{hh, ww}, 0});
  }

  for (int i = 1; i <= h; ++i) {
    if (hm == hcnt[i])
      hp.push_back(i);
  }

  for (int j = 1; j <= w; ++j) {
    if (wm == wcnt[j])
      wp.push_back(j);
  }
  int ans = 0;
  for (int i : hp) {
    for (int j : wp) {
      ans = max(ans, hm + wm - (coors.count({i, j}) ? 1 : 0));
    }
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define poi 601000
using namespace std;
typedef long long ll;
struct girl {
  int x, y;
  bool operator<(const girl &b) const { return (x ^ b.x) ? x < b.x : y < b.y; }
} a[poi];
int b[poi], ans, h, w, n, tans;
set<pair<int, int>> s;
inline int re() {
  char x = getchar();
  int k = 1, y = 0;
  while (x < '0' || x > '9') {
    if (x == '-')
      k = -1;
    x = getchar();
  }
  while (x >= '0' && x <= '9') {
    y = (y << 3) + (y << 1) + x - '0';
    x = getchar();
  }
  return y * k;
}
void wr(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    wr(x / 10);
  putchar(x % 10 + '0');
}
int lookfor(int st) {
  int x = a[st].x;
  for (int i = st;; i++) {
    if (a[i].x != x)
      break;
    s.erase(make_pair(b[a[i].y]--, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
  ans = (*--s.end()).first;
  for (int i = st;; i++) {
    if (a[i].x != x)
      return i;
    ans++;
    s.erase(make_pair(b[a[i].y]++, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
}
signed main() {
  // freopen("lca.in","r",stdin);
  // freopen("lca.out","w",stdout);
  h = re(), w = re(), n = re();
  for (int i = 1; i <= n; i++) {
    a[i].x = re(), a[i].y = re();
    b[a[i].y]++;
  }
  for (int i = 1; i <= w; i++)
    s.insert(make_pair(b[a[i].y], a[i].y));
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n;) {
    i = lookfor(i);
    tans = max(ans, tans);
  }
  wr(tans);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define poi 201000
using namespace std;
typedef long long ll;
struct girl {
  int x, y;
  bool operator<(const girl &b) const { return (x ^ b.x) ? x < b.x : y < b.y; }
} a[poi];
int b[poi], ans, h, w, n, tans;
set<pair<int, int>> s;
inline int re() {
  char x = getchar();
  int k = 1, y = 0;
  while (x < '0' || x > '9') {
    if (x == '-')
      k = -1;
    x = getchar();
  }
  while (x >= '0' && x <= '9') {
    y = (y << 3) + (y << 1) + x - '0';
    x = getchar();
  }
  return y * k;
}
void wr(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    wr(x / 10);
  putchar(x % 10 + '0');
}
int lookfor(int st) {
  int x = a[st].x;
  for (int i = st;; i++) {
    if (a[i].x != x)
      break;
    s.erase(make_pair(b[a[i].y]--, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
  ans = (*--s.end()).first;
  for (int i = st;; i++) {
    if (a[i].x != x)
      return i;
    ans++;
    s.erase(make_pair(b[a[i].y]++, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
}
signed main() {
  // freopen("lca.in","r",stdin);
  // freopen("lca.out","w",stdout);
  h = re(), w = re(), n = re();
  for (int i = 1; i <= n; i++) {
    a[i].x = re(), a[i].y = re();
    b[a[i].y]++;
  }
  for (int i = 1; i <= w; i++)
    s.insert(make_pair(b[a[i].y], a[i].y));
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n;) {
    i = lookfor(i);
    tans = max(ans, tans);
  }
  wr(tans);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  set<P> boms;
  vector<int> hLis(H + 1);
  vector<int> wLis(W + 1);

  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    hLis[h]++;
    wLis[w]++;
    boms.insert({h, w});
  }

  int hmax = *max_element(hLis.begin(), hLis.end());
  int wmax = *max_element(wLis.begin(), wLis.end());

  vector<int> hmlis;
  vector<int> wmlis;
  for (int i = 1; i <= H; i++) {
    if (hLis[i] == hmax)
      hmlis.push_back(i);
  }
  for (int i = 1; i <= W; i++) {
    if (wLis[i] == wmax)
      wmlis.push_back(i);
  }

  for (int i : hmlis) {
    for (int j : wmlis) {
      if (boms.find({i, j}) == boms.end()) {
        cout << hmax + wmax << endl;
        return 0;
      }
    }
  }
  cout << hmax + wmax - 1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  // vector<vector<bool>> map(H+1, vector<bool>(W+1, false));
  vector<P> boms(M);
  vector<int> hLis(H + 1);
  vector<int> wLis(W + 1);

  for (P &bom : boms) {
    cin >> bom.first >> bom.second;
    hLis[bom.first]++;
    wLis[bom.second]++;
  }

  int hmax = *max_element(hLis.begin(), hLis.end());
  int wmax = *max_element(wLis.begin(), wLis.end());

  vector<int> hmlis;
  vector<int> wmlis;
  for (int i = 1; i <= H; i++) {
    if (hLis[i] == hmax)
      hmlis.push_back(i);
  }
  for (int i = 1; i <= W; i++) {
    if (wLis[i] == wmax)
      wmlis.push_back(i);
  }

  for (int i : hmlis) {
    for (int j : wmlis) {
      if (find(boms.begin(), boms.end(), P(i, j)) == boms.end()) {
        cout << hmax + wmax << endl;
        return 0;
      }
    }
  }
  cout << hmax + wmax - 1 << endl;
  return 0;
}