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

#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 300005

int tree[4 * N];
vector<int> G[N];

void update(int node, int b, int e, int idx, int val) {
  if (idx < b || idx > e)
    return;
  if (b == e) {
    tree[node] += val;
    return;
  }
  int mid = (b + e) / 2;
  update(2 * node, b, mid, idx, val);
  update(2 * node + 1, mid + 1, e, idx, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].pb(y);
    update(1, 1, w, y, 1);
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    if (G[i].size()) {
      int cnt = G[i].size();
      for (int v : G[i])
        update(1, 1, w, v, -1);
      cnt += tree[1];
      ans = max(cnt, ans);
      for (int v : G[i])
        update(1, 1, w, v, 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 300005

int tree[3 * N];
vector<int> G[N];

void update(int node, int b, int e, int idx, int val) {
  if (idx < b || idx > e)
    return;
  if (b == e) {
    tree[node] += val;
    return;
  }
  int mid = (b + e) / 2;
  update(2 * node, b, mid, idx, val);
  update(2 * node + 1, mid + 1, e, idx, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].pb(y);
    update(1, 1, w, y, 1);
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    if (G[i].size()) {
      int cnt = G[i].size();
      for (int v : G[i])
        update(1, 1, w, v, -1);
      cnt += tree[1];
      ans = max(cnt, ans);
      for (int v : G[i])
        update(1, 1, w, v, 1);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int k;
  cin >> k;
  vector<int> a(k), b(k);
  for (int i = 0; i < k; i++)
    cin >> a[i] >> b[i];
  vector<int> row(n);
  vector<int> col(m);
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < k; i++) {
    --a[i];
    --b[i];
    mp[{a[i], b[i]}] = true;
    ++row[a[i]];
    ++col[b[i]];
  }
  int r = 0;
  for (int i = 0; i < n; i++)
    if (row[i] > row[r])
      r = i;
  int c = 0;
  for (int i = 0; i < m; i++)
    if (col[i] > col[c])
      c = i;
  vector<int> candRows, candCols;
  for (int i = 0; i < n; i++)
    if (row[i] == row[r])
      candRows.push_back(i);
  for (int i = 0; i < m; i++)
    if (col[i] == col[c])
      candCols.push_back(i);
  int res = 0;
  int itr = 0;
  for (int r : candRows) {
    for (int c : candCols) {
      res = max(res, row[r] + col[c] - (int)mp.count({r, c}));
      ++itr;
      if (itr > (int)1e6)
        break;
    }
  }
  cout << res << '\\n';
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int k;
  cin >> k;
  vector<int> a(k), b(k);
  for (int i = 0; i < k; i++)
    cin >> a[i] >> b[i];
  vector<int> row(n);
  vector<int> col(m);
  vector<vector<int>> mp(n, vector<int>(m));
  for (int i = 0; i < k; i++) {
    --a[i];
    --b[i];
    mp[a[i]][b[i]]++;
    ++row[a[i]];
    ++col[b[i]];
  }
  int r = 0;
  for (int i = 0; i < n; i++)
    if (row[i] > row[r])
      r = i;
  int c = 0;
  for (int i = 0; i < m; i++)
    if (col[i] > col[c])
      c = i;
  vector<int> candRows, candCols;
  for (int i = 0; i < n; i++)
    if (row[i] == row[r])
      candRows.push_back(i);
  for (int i = 0; i < m; i++)
    if (col[i] == col[c])
      candCols.push_back(i);
  int res = 0;
  int itr = 0;
  for (int r : candRows) {
    for (int c : candCols) {
      res = max(res, row[r] + col[c] - mp[r][c]);
      ++itr;
      if (itr > (int)3e5)
        break;
    }
  }
  cout << res << '\\n';
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl '\\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;

struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  umap<int, int> row, col;
  umap<pair<int, int>, int, HASH> grid;
  int mx_r = 0, mx_c = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[x]++;
    col[y]++;
    grid[{x, y}] = 1;
    mx_r = max(mx_r, row[x]);
    mx_c = max(mx_c, col[y]);
  }
  vector<int> a, b;
  for (auto i : row) {
    if (i.second == mx_r)
      a.push_back(i.first);
  }
  for (auto i : col) {
    if (i.second == mx_c)
      b.push_back(i.first);
  }
  int ans = 0;
  int highest = mx_r + mx_c;
  for (int i : a) {
    for (int j : b) {
      ans = max(ans, mx_r + mx_c - grid[{i, j}]);
      if (ans == highest)
        goto end;
    }
  }
end:;
  printf("%d", ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;

struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  umap<int, int> row, col;
  umap<pair<int, int>, int, HASH> grid;
  int mx_r = 0, mx_c = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[x]++;
    col[y]++;
    grid[{x, y}] = 1;
    mx_r = max(mx_r, row[x]);
    mx_c = max(mx_c, col[y]);
  }
  vector<int> a, b;
  for (auto i : row) {
    if (i.second == mx_r)
      a.push_back(i.first);
  }
  for (auto i : col) {
    if (i.second == mx_c)
      b.push_back(i.first);
  }
  int ans = 0;
  int highest = h + w - 1;
  for (int i : a) {
    for (int j : b) {
      ans = max(ans, mx_r + mx_c - grid[{i, j}]);
      if (ans == highest)
        goto end;
    }
  }
end:;
  printf("%d", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long int
#define pb push_back
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define pre(i, j, n) for (ll i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;
#define br "\\n"
#define MAX 1000001
#define ff first
#define ss second
ll mod = 1e9 + 7;
ll maxi = 3e5 + 1;

ll h, w, m;
vll x, y;
set<pll> s;
void solve() {
  cin >> h >> w >> m;
  x.assign(h + 1, 0);
  y.assign(w + 1, 0);
  ll maxx = 1, maxy = 1;
  rep(i, 0, m) {
    ll x0, y0;
    cin >> x0 >> y0;
    x[x0]++;
    y[y0]++;
    maxx = max(maxx, x[x0]);
    maxy = max(maxy, y[y0]);
    s.insert({x0, y0});
  }
  vll vx, vy;
  rep(i, 0, h + 1) {
    if (x[i] == maxx)
      vx.pb(i);
  }
  rep(i, 0, w + 1) {
    if (y[i] == maxy)
      vy.pb(i);
  }
  ll ans = maxx + maxy - 1;
  for (auto i : vx) {
    for (auto j : vy) {
      if (s.find({i, j}) == s.end()) {
        cout << x[i] + y[j];
        return;
      }
    }
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin >> t;
  rep(i, 0, t) { solve(); }
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define pb push_back
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define pre(i, j, n) for (ll i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;
#define br "\\n"
#define MAX 1000001
#define ff first
#define ss second
ll mod = 1e9 + 7;
ll maxi = 3e5 + 1;

ll h, w, m;
vll x, y;
set<pll> s;
void solve() {
  cin >> h >> w >> m;
  x.assign(h + 1, 0);
  y.assign(w + 1, 0);
  ll maxx = 1, maxy = 1;
  rep(i, 0, m) {
    ll x0, y0;
    cin >> x0 >> y0;
    x[x0]++;
    y[y0]++;
    maxx = max(maxx, x[x0]);
    maxy = max(maxy, y[y0]);
    s.insert({x0, y0});
  }
  vll vx, vy;
  rep(i, 0, h + 1) {
    if (x[i] == maxx)
      vx.pb(i);
  }
  rep(i, 0, w + 1) {
    if (y[i] == maxy)
      vy.pb(i);
  }
  ll ans = 0;
  for (auto i : vx) {
    for (auto j : vy) {
      ll cc = x[i] + y[j];
      if (s.find({i, j}) != s.end())
        cc--;
      ans = max(ans, cc);
    }
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin >> t;
  rep(i, 0, t) { solve(); }
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> p(h, 0), q(w, 0);
  set<P> st;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    st.insert({a, b});
    p[a]++;
    q[b]++;
  }
  vector<int> candih, candiw;
  int maxh = 0, maxw = 0;
  rep(i, h - 1) {
    if (p[maxh] < p[i + 1]) {
      maxh = i + 1;
    }
  }
  rep(i, w - 1) {
    if (q[maxw] < q[i + 1]) {
      maxw = i + 1;
    }
  }
  rep(i, h) {
    if (p[maxh] == p[i]) {
      candih.push_back(i);
    }
  }
  rep(i, w) {
    if (q[maxw] == q[i]) {
      candiw.push_back(i);
    }
  }
  int ans = p[maxh] + q[maxw];
  bool ok = false;
  for (auto &v : candih) {
    for (auto &vv : candiw) {
      if (st.find({v, vv}) == st.end()) {
        // cout<<v<<vv<<endl;
        ok = true;
      }
      if (ok)
        break;
    }
    if (ok)
      break;
  }
  if (!ok)
    ans--;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> p(h, 0), q(w, 0);
  vector<vector<int>> check(h, vector<int>(w, 0));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    check[a][b] = 1;
    p[a]++;
    q[b]++;
  }
  vector<int> candih, candiw;
  int maxh = 0, maxw = 0;
  rep(i, h - 1) {
    if (p[maxh] < p[i + 1]) {
      maxh = i + 1;
    }
  }
  rep(i, w - 1) {
    if (q[maxw] < q[i + 1]) {
      maxw = i + 1;
    }
  }
  rep(i, h) {
    if (p[maxh] == p[i]) {
      candih.push_back(i);
    }
  }
  rep(i, w) {
    if (q[maxw] == q[i]) {
      candiw.push_back(i);
    }
  }
  int ans = p[maxh] + q[maxw];
  bool ok = false;
  for (auto &v : candih) {
    for (auto &vv : candiw) {
      if (check[v][vv] == 0) {
        ok = true;
      }
    }
  }
  if (!ok)
    ans--;
  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 ii = pair<int, int>;

const int MAX_N = 1e6;
int rc[MAX_N];
int cc[MAX_N];
int h, w, m;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  set<ii> pos;
  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    rc[x] += 1;
    cc[y] += 1;
    pos.insert({x, y});
  }

  int max_val_cols = 0;
  int max_col_idx = 0;
  int max_val_rows = 0;
  int max_row_idx = 0;

  for (int i = 1; i <= h; i++) {
    int row_v = rc[i];
    if (row_v > max_val_rows) {
      max_val_rows = row_v;
      max_row_idx = i;
    }
  }

  for (int i = 1; i <= w; i++) {
    int col_v = cc[i];
    if (pos.count(make_pair(max_row_idx, i)))
      col_v--;
    if (col_v > max_val_cols) {
      max_val_cols = col_v;
      max_col_idx = i;
    }
  }

  int ans1 = max_val_cols + max_val_rows;

  max_row_idx = max_val_rows = max_col_idx = max_val_cols = 0;

  for (int i = 1; i <= w; i++) {
    int col_v = cc[i];
    if (col_v > max_val_cols) {
      max_val_cols = col_v;
      max_col_idx = i;
    }
  }

  for (int i = 1; i <= h; i++) {
    int row_v = rc[i];
    if (pos.count(make_pair(i, max_col_idx)))
      row_v--;
    if (row_v > max_val_rows) {
      max_val_rows = row_v;
      max_row_idx = i;
    }
  }

  int ans2 = max_val_cols + max_val_rows;

  cout << max(ans2, ans1) << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX_N = 1e6;
int rc[MAX_N];
int cc[MAX_N];
int h, w, m;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  set<ii> pos;
  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    rc[x] += 1;
    cc[y] += 1;
    pos.insert({x, y});
  }

  int total_max = 0;
  for (int i = 1; i <= h; i++) {
    int row_v = rc[i];
    int it_max_c = 0;
    for (int j = 1; j <= w; j++) {
      int val = cc[j];
      if (pos.count(make_pair(i, j))) {
        val--;
      }
      if (val > it_max_c)
        it_max_c = val;
    }
    int total_sum = row_v + it_max_c;
    if (total_sum > total_max)
      total_max = total_sum;
  }

  cout << total_max << "\\n";
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;

int main() {

  ll r, c, m;
  cin >> r >> c >> m;

  vector<ll> R(r);
  vector<ll> C(c);

  ll max_row = 0, max_col = 0;

  map<pair<ll, ll>, bool> M;

  while (m--) {
    ll i, j;
    cin >> i >> j;
    R[i - 1]++;
    C[j - 1]++;

    M[make_pair(i - 1, j - 1)] = 1;

    max_row = max(max_row, R[i - 1]);
    max_col = max(max_col, C[j - 1]);
  }

  vector<ll> max_rows, max_cols;

  for (int i = 0; i < r; i++) {
    if (R[i] == max_row)
      max_rows.push_back(i);
  }

  for (int i = 0; i < c; i++) {
    if (C[i] == max_col)
      max_cols.push_back(i);
  }

  ll ans = max_row + max_col - 1;
  bool f = 0;

  for (int i = 0; i < max_rows.size() and !f; i++) {
    for (int j = 0; j < max_cols.size() and !f; j++) {
      if (M[make_pair(max_rows[i], max_cols[j])] == 0) {
        f = 1;
      }
    }
  }

  if (f)
    ans++;

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

Error: TLE

Fixed submission:

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

typedef long long ll;

int main() {

  ll r, c, m;
  cin >> r >> c >> m;

  vector<ll> R(r);
  vector<ll> C(c);

  map<pair<int, int>, bool> M;

  while (m--) {
    ll i, j;
    cin >> i >> j;
    M[make_pair(i - 1, j - 1)] = 1;
    R[i - 1]++;
    C[j - 1]++;
  }

  ll ans = 0;

  for (ll i = 0; i < r; i++) {
    for (ll j = 0; j < c; j++) {
      ll cur = R[i] + C[j];
      if (M[make_pair(i, j)] == 1)
        cur--;
      ans = max(ans, cur);
    }
  }

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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout << "here\\n"
#define MOD 1000000009

const int MAXN = 3e5 + 15;

using namespace std;

int R[MAXN], C[MAXN];

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  int mrc = 0, mcc = 0, mr, mc;
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    R[a]++;
    C[b]++;
    if (C[b] > mcc) {
      mcc = C[b];
      mc = b;
    }
    if (R[a] > mrc) {
      mrc = R[a];
      mr = a;
    }
    mp[{a, b}] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, mcc + R[i + 1] - mp[{i + 1, mc}]);
  }
  for (int i = 0; i < m; i++) {
    ans = max(ans, mrc + C[i + 1] - mp[{mr, i + 1}]);
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);

  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\\n";
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout << "here\\n"
#define MOD 1000000009

const int MAXN = 2e5 + 15;

using namespace std;

int R[MAXN], C[MAXN];

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  int mrc = 0, mcc = 0, mr, mc;
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    R[a]++;
    C[b]++;
    if (C[b] > mcc) {
      mcc = C[b];
      mc = b;
    }
    if (R[a] > mrc) {
      mrc = R[a];
      mr = a;
    }
    mp[{a, b}] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, mcc + R[i + 1] - mp[{i + 1, mc}]);
  }
  for (int i = 0; i < m; i++) {
    ans = max(ans, mrc + C[i + 1] - mp[{mr, i + 1}]);
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);

  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\\n";
  }

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

#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
// #define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

const int inf = (int)1e9;

int main(void) {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> mp1, mp2;
  map<P, bool> exist;
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    mp1[hi]++;
    mp2[wi]++;
    exist[P(hi, wi)] = true;
  }
  int colmax = 0, rowmax = 0;
  for (auto [x, y] : mp1) {
    colmax = max(colmax, y);
  }
  for (auto [x, y] : mp2) {
    rowmax = max(rowmax, y);
  }
  set<P> p1, p2;
  for (auto [x, y] : mp1) {
    if (colmax == y) {
      p1.insert(P(x, y));
    }
  }
  for (auto [x, y] : mp2) {
    if (rowmax == y) {
      p2.insert(P(x, y));
    }
  }
  int ans = 0;
  for (auto itr1 = p1.begin(); itr1 != p1.end(); ++itr1) {
    for (auto itr2 = p2.begin(); itr2 != p2.end(); ++itr2) {
      int num = (itr1->second) + (itr2->second);
      int x = itr1->first;
      int y = itr2->first;
      if (exist[P(x, y)])
        num--;
      else {
        cout << num << endl;
        return 0;
      }
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
// #define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

const int inf = (int)1e9;

int main(void) {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> mp1, mp2;
  map<P, bool> exist;
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    mp1[hi]++;
    mp2[wi]++;
    exist[P(hi, wi)] = true;
  }
  int colmax = 0, rowmax = 0;
  for (auto [x, y] : mp1) {
    colmax = max(colmax, y);
  }
  for (auto [x, y] : mp2) {
    rowmax = max(rowmax, y);
  }
  set<P> p1, p2;
  for (auto [x, y] : mp1) {
    if (colmax == y) {
      p1.insert(P(x, y));
    }
  }
  for (auto [x, y] : mp2) {
    if (rowmax == y) {
      p2.insert(P(x, y));
    }
  }
  int ans = 0;
  for (auto itr1 = p1.begin(); itr1 != p1.end(); ++itr1) {
    for (auto itr2 = p2.begin(); itr2 != p2.end(); ++itr2) {
      int num = (itr1->second) + (itr2->second);
      int x = itr1->first;
      int y = itr2->first;
      if (exist[P(x, y)])
        num--;
      ans = max(ans, num);
    }
  }
  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 sayyes cout << "Yes" << endl;
#define sayno cout << "No" << endl;
using namespace std;
typedef long long ll;
const double PI = acos(-1);
typedef pair<int, int> P;
const int mod = 1e9 + 7;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<ll> hrow(h, 0);
  vector<ll> wrow(w, 0);
  vector<P> data;
  vector<ll> hb(m, 0);
  vector<ll> wb(m, 0);
  rep(i, m) {
    int ht, wt;
    cin >> ht >> wt;
    hrow[ht - 1]++;
    wrow[wt - 1]++;
    hb[i] = ht - 1;
    wb[i] = wt - 1;
  }
  ll hindex = *max_element(hrow.begin(), hrow.end());
  ll windex = *max_element(wrow.begin(), wrow.end());

  ll ans = hindex + windex;
  ll num = count(hrow.begin(), hrow.end(), hindex) *
           count(wrow.begin(), wrow.end(), windex);
  rep(i, m) {
    if ((wrow[wb[i]] + hrow[hb[i]]) == ans)
      num--;
  }

  cout << ans - (num == 0);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sayyes cout << "Yes" << endl;
#define sayno cout << "No" << endl;
using namespace std;
typedef long long ll;
const double PI = acos(-1);
typedef pair<int, int> P;
const int mod = 1e9 + 7;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<ll> hrow(h, 0);
  vector<ll> wrow(w, 0);
  // vector<vector<ll>> a(h);
  vector<vector<bool>> ex(h, vector<bool>(w, false));
  rep(i, m) {
    int ht, wt;
    cin >> ht >> wt;
    // a[ht-1].push_back(wt-1);
    hrow[ht - 1]++;
    wrow[wt - 1]++;
    ex[ht - 1][wt - 1] = true;
  }
  ll hindex = max_element(hrow.begin(), hrow.end()) - hrow.begin();
  // ll windex=max_element(wrow.begin(),wrow.end())-wrow.begin();
  ll maxh = 0;
  rep(i, w) {
    ll bnum = 0;
    bnum += wrow[i];
    bnum += hrow[hindex];
    if (ex[hindex][i]) {
      bnum--;
    }
    if (maxh < bnum) {
      maxh = bnum;
    }
  }

  cout << maxh;
}