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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
// #define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main() {
  int H, W, m;
  cin >> H >> W >> m;
  vector<int> h(m), w(m);
  map<Pi, bool> used;
  rep(i, m) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    used[{h[i], w[i]}] = true;
  }
  vector<int> cnth(H), cntw(W);
  rep(i, m) {
    cnth[h[i]]++;
    cntw[w[i]]++;
  }
  int maxh = *max_element(cnth.begin(), cnth.end());
  int maxw = *max_element(cntw.begin(), cntw.end());
  vector<int> v1, v2;
  rep(i, H) {
    if (cnth[i] == maxh)
      v1.push_back(i);
  }
  rep(i, W) {
    if (cntw[i] == maxw)
      v2.push_back(i);
  }
  int ans = maxh + maxw - 1;
  int cnt = 0;
  for (auto u : used) {
    if (cnth[u.first.first] == maxh && cntw[u.first.second] == maxw)
      cnt++;
  }
  if (cnt != (int)(v1.size() * v2.size()))
    ans++;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
// #define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main() {
  int H, W, m;
  cin >> H >> W >> m;
  vector<int> h(m), w(m);
  map<Pi, bool> used;
  rep(i, m) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    used[{h[i], w[i]}] = true;
  }
  vector<int> cnth(H), cntw(W);
  rep(i, m) {
    cnth[h[i]]++;
    cntw[w[i]]++;
  }
  int maxh = *max_element(cnth.begin(), cnth.end());
  int maxw = *max_element(cntw.begin(), cntw.end());
  vector<int> v1, v2;
  rep(i, H) {
    if (cnth[i] == maxh)
      v1.push_back(i);
  }
  rep(i, W) {
    if (cntw[i] == maxw)
      v2.push_back(i);
  }
  int ans = maxh + maxw - 1;
  rep(i, v1.size()) rep(j, v2.size()) {
    if (!used[{v1[i], v2[j]}]) {
      ans = maxh + maxw;
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 1000000007;
signed main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  map<P, int> bomb;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    bomb[{a, b}] += 1;
  }
  vector<lint> rsm(h + 1, 0);
  vector<lint> csm(w + 1, 0);
  for (auto const &it : bomb) {
    csm[it.first.second] += it.second;
    rsm[it.first.first] += it.second;
  }
  int cmx = -1;
  rep1(i, w) { cmx = max(cmx, csm[i]); }
  int rmx = -1;
  rep1(i, h) { rmx = max(rmx, rsm[i]); }
  vector<int> rmxind;
  rep1(i, h) {
    if (rsm[i] == rmx)
      rmxind.push_back(i);
  }
  lint res = -1;
  rep1(i, w) {
    if (csm[i] == cmx) {
      for (auto &val : rmxind) {
        int add = bomb[{val, i}];
        res = max(res, cmx + rmx - add);
        if (add == 0) {
          cout << res << "\\n";
          return 0;
        }
      }
    }
  }
  cout << res << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 1000000007;
signed main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  vector<vector<int>> bomb(h + 1, vector<int>(w + 1, 0));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    bomb[a][b] += 1;
  }
  vector<lint> rsm(h + 1, 0);
  vector<lint> csm(w + 1, 0);
  rep1(i, h) {
    rep1(j, w) { rsm[i] += bomb[i][j]; }
  }
  rep1(j, w) {
    rep1(i, h) { csm[j] += bomb[i][j]; }
  }
  lint res = -1;
  rep1(i, h) {
    rep1(j, w) {
      lint buf = csm[j] + rsm[i] - bomb[i][j];
      res = max(res, buf);
    }
  }
  cout << res << "\\n";
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} _io;
typedef long long ll;
typedef long double db;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(H + 1, 0), w(W + 1, 0);
  vector<pair<int, int>> pii;

  for (int i = 1; i <= M; ++i) {
    int a, b;
    cin >> a >> b;
    pii.push_back({a, b});
    ++h[a];
    ++w[b];
  }
  ll hcnt = 0, wcnt = 0, pcnt = 0;
  ll mh = *max_element(h.begin(), h.end());
  ll mw = *max_element(w.begin(), w.end());
  for (int i = 1; i <= H; ++i)
    if (h[i] == mh)
      ++hcnt;
  for (int i = 1; i <= W; ++i)
    if (w[i] == mw)
      ++wcnt;
  for (auto i : pii)
    if (h[i.first] == mh && w[i.second] == mw)
      ++pcnt;

  if (pcnt == hcnt * wcnt)
    cout << mh + mw - 1 << endl;
  else
    cout << mh + mw << endl;

  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} _io;
typedef long long ll;
typedef long double db;

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

  vector<int> a(h + 1, 0), b(w + 1, 0);
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    mp[make_pair(x, y)] = 1;
    ++a[x];
    ++b[y];
  }

  ll ans = -0x3f3f3f3f;
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j) {
      if (mp[make_pair(i, j)] == 1) {
        ans = max(ans, (ll)(a[i] + b[j] - 1));
      } else
        ans = max(ans, (ll)(a[i] + b[j]));
    }

  cout << ans << endl;

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

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define _USE_MATH_DEFINES
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define ll long long int
#define pii pair<ll, ll>
#define pb push_back
#define MIN -9, 223, 372, 036, 854, 775
#define N 100005
#define all(v) v.begin(), v.end()

void solve() {
  ll i, j, k, n, ans = 0, m, mx = 0, my = 0, a, b, x, y;
  cin >> n >> m >> k;
  set<pii> s;
  unordered_map<ll, ll> tx, ty;
  vector<ll> vx, vy;
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    s.insert({a, b});
    tx[a]++;
    ty[b]++;
    if (tx[a] > mx) {
      vx.clear();
      mx = tx[a];
      vx.push_back(a);
    } else if (tx[a] == mx) {
      vx.push_back(a);
    }

    if (ty[b] > my) {
      my = ty[b];
      vy.clear();
      vy.push_back(b);
    } else if (ty[b] == my) {
      vy.push_back(b);
    }
  }

  if (k <= 2) {
    cout << k;
    return;
  }
  ans = mx + my;
  ll f = 0;
  for (i = 0; i < vx.size(); i++) {
    for (j = 0; j < vy.size(); j++) {
      if (s.find({vx[i], vy[j]}) == s.end()) {
        f = 1;
        break;
      }
    }
  }

  if (!f)
    ans--;

  cout << ans;
}

int main() {
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}

/*
5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4
*/


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define _USE_MATH_DEFINES
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define ll long long int
#define pii pair<ll, ll>
#define pb push_back
#define MIN -9, 223, 372, 036, 854, 775
#define N 100005
#define all(v) v.begin(), v.end()

void solve() {
  ll i, j, k, n, ans = 0, m, x, y, dx, dy, a, b;
  cin >> n >> m >> k;
  unordered_map<ll, ll> tx, ty;
  vector<vector<ll>> vis(n + 1, vector<ll>(m + 1, 0));
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    vis[a][b] = 1;
    tx[a]++;
    ty[b]++;
  }

  if (k <= 1) {
    cout << k;
    return;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (vis[i][j] == 0)
        ans = max(ans, tx[i] + ty[j]);
      else
        ans = max(ans, tx[i] + ty[j] - 1);
    }
  }
  cout << ans;
}

int main() {
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}

/*
5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4
*/
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M);
  vector<int> w(M);
  rep(i, M) cin >> h[i] >> w[i];
  vector<int> bomb(M, 0);
  // 各行・列の爆弾個数を取得
  vector<int> a(H, 0);
  vector<int> b(W, 0);
  // vector<vector<int>> c(H,vector<int>(W,0));
  rep(i, M) {
    a[h[i] - 1]++;
    b[w[i] - 1]++;
    // c[h[i]-1][w[i]-1]++;
  }

  int am = 0, bm = 0;
  rep(i, H) am = max(am, a[i]);
  rep(i, W) bm = max(bm, b[i]);
  int acnt = 0, bcnt = 0;
  rep(i, H) if (a[i] == am) acnt++;
  rep(i, W) if (b[i] == bm) bcnt++;
  ll cnt = 0;
  rep(i, M) {
    if (a[h[i] - 1] == am && b[w[i] - 1] == bm)
      cnt++;
  }
  ll ans;
  if (cnt >= (ll)acnt * bcnt)
    ans = am + bm - 1;
  else
    ans = am + bm;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M);
  vector<int> w(M);
  rep(i, M) cin >> h[i] >> w[i];
  vector<int> bomb(M, 0);
  // 各行・列の爆弾個数を取得
  vector<int> a(H, 0);
  vector<int> b(W, 0);
  vector<vector<int>> c(H, vector<int>(W, 0));
  rep(i, M) {
    a[h[i] - 1]++;
    b[w[i] - 1]++;
    c[h[i] - 1][w[i] - 1]++;
  }

  int am = 0, bm = 0;
  rep(i, H) am = max(am, a[i]);
  rep(i, W) bm = max(bm, b[i]);
  int acnt = 0, bcnt = 0;
  rep(i, H) if (a[i] == am) acnt++;
  rep(i, W) if (b[i] == bm) bcnt++;
  int cnt = 0;
  rep(i, M) {
    if (a[h[i] - 1] == am && b[w[i] - 1] == bm)
      cnt++;
  }
  int ans;
  if (cnt >= acnt * bcnt)
    ans = am + bm - 1;
  else
    ans = am + bm;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long int H, W, M, a, b, mah, maw, n[300001], m[300001],
    ma = 0, n1 = 0, m1 = 0, h[1000000], w[1000000];
int main() {
  cin >> H >> W >> M;
  for (int i = 1; i <= M; i++) {
    cin >> n[i] >> m[i];
    h[n[i]] += 1;
    w[m[i]] += 1;
  }
  a = 0;
  b = 0;
  for (int i = 1; i <= H; i++)
    if (h[i] > mah)
      mah = h[i];
  for (int i = 1; i <= H; i++)
    if (h[i] == mah) {
      a++;
    }

  for (int j = 1; j <= W; j++)
    if (w[j] > maw)
      maw = w[j];
  for (int i = 1; i <= W; i++)
    if (w[i] == maw) {
      b++;
    }
  ma = a * b;

  for (int z = 1; z <= M; z++)
    if ((h[n[z]] == mah) && (w[m[z]] == maw))
      m1++;

  if (ma == m1)
    cout << maw + mah - 1;
  else
    cout << maw + mah;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int H, W, M, a, b, n[300000], m[300000], ma = 0, n1 = 0, m1 = 0,
                                                   h[10000], w[10000];
int main() {
  cin >> H >> W >> M;
  for (int i = 1; i <= M; i++) {
    cin >> n[i] >> m[i];
    h[n[i]] += 1;
    w[m[i]] += 1;
  }
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++) {
      b = h[i] + w[j];
      for (int a = 1; a <= M; a++)
        if ((i == n[a]) && (j == m[a]))
          b = b - 1;
      if (b > ma) {
        ma = b;
        m1 = i;
        n1 = j;
      }
    }
  cout << ma;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<ll, ll>> row, col;
  map<ll, ll> mr, mc;
  map<pair<ll, ll>, ll> ma;
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    mr[x - 1]++;
    mc[y - 1]++;
    ma[make_pair(x - 1, y - 1)]++;
  }
  for (auto i : mr)
    row.push_back(make_pair(i.second, i.first));
  for (auto i : mc)
    col.push_back(make_pair(i.second, i.first));
  sort(row.begin(), row.end());
  reverse(row.begin(), row.end());
  sort(col.begin(), col.end());
  reverse(col.begin(), col.end());
  ll ans = 0, flag = 0;
  for (ll i = 0; i < (ll)row.size(); i++) {
    if (row[i].first != row[0].first)
      break;
    for (ll j = 0; j < (ll)col.size(); j++) {
      ll tt = 0;
      if (col[j].first != col[0].first)
        break;
      ll currAns = row[i].first + col[j].first;
      tt = ma[make_pair(row[i].second, col[j].second)];
      if (tt > 0ll)
        currAns--;
      ans = max(ans, currAns);
      if (tt == 0ll) {
        break;
        flag = 1;
      }
    }
    if (flag)
      break;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<ll, ll>> row, col;
  map<ll, ll> mr, mc;
  map<pair<ll, ll>, ll> ma;
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    mr[x - 1]++;
    mc[y - 1]++;
    ma[make_pair(x - 1, y - 1)]++;
  }
  for (auto i : mr)
    row.push_back(make_pair(i.second, i.first));
  for (auto i : mc)
    col.push_back(make_pair(i.second, i.first));
  sort(row.begin(), row.end());
  reverse(row.begin(), row.end());
  sort(col.begin(), col.end());
  reverse(col.begin(), col.end());
  ll ans = 0;
  for (ll i = 0; i < (ll)row.size(); i++) {
    if (row[i].first != row[0].first)
      break;
    for (ll j = 0; j < (ll)col.size(); j++) {
      if (col[j].first != col[0].first)
        break;
      ll currAns = row[i].first + col[j].first;
      ll tt = ma[make_pair(row[i].second, col[j].second)];
      // cout << row[i].second << " " << col[j].second << " " <<
      // ma[make_pair(row[i].second,col[j].second)] << endl; cout<<tt<<endl;
      if (tt > 0ll)
        currAns--;
      ans = max(ans, currAns);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1001001001;

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

  vector<int> cnth(h), cntw(w);
  set<P> st;

  rep(i, m) {
    int th, tw;
    cin >> th >> tw;
    --th;
    --tw;
    cnth[th]++;
    cntw[tw]++;
    st.emplace(th, tw);
  }

  int ans = 0;
  int maxh = 0;
  int maxw = 0;
  rep(i, h) chmax(maxh, cnth[i]);
  rep(i, w) chmax(maxw, cntw[i]);
  vector<int> th, tw;
  rep(i, h) if (maxh == cnth[i]) th.push_back(i);
  rep(i, w) if (maxw == cntw[i]) tw.push_back(i);

  ans = maxh + maxw;
  for (int i : th)
    for (int j : tw) {
      if (st.count(P(i, j)))
        continue;
      cout << ans << endl;
      return 0;
    }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<vector<int>> bomb(h, vector<int>(w));
  rep(i, m) {
    int th, tw;
    cin >> th >> tw;
    --th;
    --tw;
    bomb[th][tw]++;
  }

  vector<vector<int>> left(h, vector<int>(w));
  vector<vector<int>> right(h, vector<int>(w));
  vector<vector<int>> up(h, vector<int>(w));
  vector<vector<int>> down(h, vector<int>(w));

  int cur = 0;
  auto add = [&](vector<vector<int>> &vec, int i, int j) {
    cur += bomb[i][j];
    vec[i][j] += cur;
  };

  // left to right
  rep(i, h) {
    cur = 0;
    rep(j, w) {
      cur += bomb[i][j];
      left[i][j] += cur;
    }
  }

  // right to left
  rep(i, h) {
    cur = 0;
    for (int j = w - 1; j >= 0; --j) {
      cur += bomb[i][j];
      right[i][j] += cur;
    }
  }
  // up to down
  rep(j, w) {
    cur = 0;
    rep(i, h) {
      cur += bomb[i][j];
      up[i][j] += cur;
    }
  }

  // down to up
  rep(j, w) {
    cur = 0;
    for (int i = h - 1; i >= 0; --i) {
      cur += bomb[i][j];
      down[i][j] += cur;
    }
  }

  int ans = 0;

  rep(i, h) rep(j, w) {
    cur = left[i][j] + right[i][j] + up[i][j] + down[i][j];
    cur -= bomb[i][j] * 3;
    chmax(ans, cur);
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(H + 1, 0);
  vector<int> w(W + 1, 0);
  set<pair<int, int>> target;
  rep(i, 0, M) {
    int t1, t2;
    cin >> t1 >> t2;
    h[t1]++;
    w[t2]++;
    target.insert(make_pair(t1, t2));
  }
  vector<pair<int, int>> hi;
  rep(i, 0, H + 1) hi.push_back(make_pair(h[i], i));
  vector<pair<int, int>> wi;
  rep(i, 0, W + 1) wi.push_back(make_pair(w[i], i));
  sort(all(hi));
  sort(all(wi));
  ll ans = hi[H].first + wi[W].first - 1;
  bool found = 0;
  for (int i = H; i >= 0; i--) {
    if (hi[i].first != hi[H].first || found)
      break;
    for (int j = W; j >= 0; j--) {
      if (wi[j].first != wi[W].first || found)
        break;
      else if (!target.count(make_pair(hi[i].second, wi[j].second)))
        found = 1;
    }
  }
  if (found)
    cout << ans + 1 << endl;
  else
    cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(H + 1, 0);
  vector<int> w(W + 1, 0);
  vector<vector<bool>> target(H + 1, vector<bool>(W + 1, 0));
  rep(i, 0, M) {
    int t1, t2;
    cin >> t1 >> t2;
    h[t1]++;
    w[t2]++;
    target[t1][t2] = 1;
  }
  vector<pair<int, int>> hi;
  rep(i, 0, H + 1) hi.push_back(make_pair(h[i], i));
  vector<pair<int, int>> wi;
  rep(i, 0, W + 1) wi.push_back(make_pair(w[i], i));
  sort(all(hi));
  sort(all(wi));
  ll ans = hi[H].first + wi[W].first - 1;
  bool found = 0;
  for (int i = H; i >= 0; i--) {
    if (hi[i].first != hi[H].first || found)
      break;
    for (int j = W; j >= 0; j--) {
      if (wi[j].first != wi[W].first || found)
        break;
      else if (!target[hi[i].second][wi[j].second])
        found = 1;
    }
  }
  if (found)
    cout << ans + 1 << endl;
  else
    cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long H, W, N;
  cin >> H >> W >> N;
  vector<pair<long, long>> ta(H), yo(W);
  map<pair<long, long>, long> mp;
  for (int i = 0; i < H; i++)
    ta.at(i).second = i;
  for (int i = 0; i < W; i++)
    yo.at(i).second = i;
  long h, w;
  for (int i = 0; i < N; i++) {
    cin >> h >> w;
    h--;
    w--;
    ta.at(h).first++;
    yo.at(w).first++;
    mp[make_pair(h, w)]++;
  }
  sort(ta.begin(), ta.end());
  sort(yo.begin(), yo.end());
  long ans = 0, flag = 0, maxt = ta.at(H - 1).first, maxy = yo.at(W - 1).first;
  for (int i = H - 1; i >= 0; i--) {
    if (maxt - ta.at(i).first >= 1)
      break;
    for (int j = W - 1; j >= 0; j--) {
      if (maxy - yo.at(j).first >= 1)
        break;
      if (mp.count(make_pair(ta.at(i).second, yo.at(j).second)) == 0) {
        ans = max(ans, ta.at(i).first + yo.at(j).first);
        flag = 1;
        break;
      } else
        ans = max(ans, ta.at(i).first + yo.at(j).first - 1);
    }
    if (flag == 1)
      break;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long H, W, N;
  cin >> H >> W >> N;
  vector<pair<long, long>> ta(H), yo(W);
  map<pair<long, long>, long> mp;
  for (int i = 0; i < H; i++)
    ta.at(i).second = i;
  for (int i = 0; i < W; i++)
    yo.at(i).second = i;
  long h, w;
  for (int i = 0; i < N; i++) {
    cin >> h >> w;
    h--;
    w--;
    ta.at(h).first++;
    yo.at(w).first++;
    mp[make_pair(h, w)]++;
  }
  sort(ta.begin(), ta.end());
  sort(yo.begin(), yo.end());
  reverse(ta.begin(), ta.end());
  reverse(yo.begin(), yo.end());
  long ans = 0, sub, maxt = ta.at(0).first, maxy = yo.at(0).first;
  for (int i = 0; i < H; i++) {
    if (maxt - ta.at(i).first >= 1)
      break;
    for (int j = 0; j < W; j++) {
      if (maxy - yo.at(j).first >= 1)
        break;
      if (mp.count(make_pair(ta.at(i).second, yo.at(j).second)) > 0)
        ans = max(ans, ta.at(i).first + yo.at(j).first - 1);
      else
        ans = max(ans, ta.at(i).first + yo.at(j).first);
    }
  }
  cout << ans << endl;
  return 0;
}