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

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\\n'
#define pii pair<int, int>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a, b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mex 300005

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, q;
  cin >> n >> m >> q;
  int arr[m] = {0}, mexcol = 0;
  map<int, vector<int>> mp;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    mp[x].pb(y);
    arr[y]++;
    mexcol = max(mexcol, arr[y]);
  }
  int freq[m + 1] = {0};
  for (int i = 0; i < m; i++)
    freq[arr[i]]++;
  int ans = 0;
  for (auto it : mp) {
    int ans1 = sz(it.ss), mex1 = 0, freq1 = 0;
    for (int t : it.ss) {
      if (arr[t] > mex1) {
        mex1 = arr[t];
        freq1 = 1;
      } else if (arr[t] == mex1)
        freq1++;
    }
    if (mex1 == mexcol && freq1 == freq[mex1])
      ans1 += mex1 - 1;
    else
      ans1 += mexcol;
    ans = max(ans, ans1);
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\\n'
#define pii pair<int, int>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a, b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mex 1005
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}, dis[mex][mex], n, m;
string mat[mex];
queue<pii> q;

inline bool ok(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }

inline void dfs(int x, int y, int val) {
  dis[x][y] = val;
  for (int i = 0; i < 4; i++) {
    int a = x + dx[i], b = y + dy[i];
    if (ok(a, b) && mat[a][b] != '#' && dis[a][b] == -1) {
      dfs(a, b, val);
      q.push(mp(a, b));
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  for (int i = 0; i < n; i++)
    cin >> mat[i];
  q.push(mp(a, b));
  fill(dis, -1);
  dis[a][b] = 0;
  while (!q.empty()) {
    pii p = q.front();
    q.pop();
    dfs(p.ff, p.ss, dis[p.ff][p.ss]);
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int x = p.ff + i, y = p.ss + j;
        if (ok(x, y) && mat[x][y] != '#' && dis[x][y] == -1) {
          dis[x][y] = dis[p.ff][p.ss] + 1;
          q.push(mp(x, y));
          dfs(x, y, dis[x][y]);
        }
      }
    }
  }
  cout << dis[c][d] << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<pair<int, int>, int> t;
  vector<pair<int64_t, int>> th(h, {0, 0}), tw(w, {0, 0});
  for (auto i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    t[{x, y}]++;
    th[x].first++;
    tw[y].first++;
    th[x].second = x;
    tw[y].second = y;
  }
  sort(th.begin(), th.end(), greater<>());
  sort(tw.begin(), tw.end(), greater<>());
  int64_t ans = th.front().first + tw.front().first;
  for (auto elm1 = th.begin(); elm1->first == th.front().first; elm1++) {
    bool flg = false;
    for (auto elm2 = tw.begin(); elm2->first == tw.front().first; elm2++) {
      if (t[{elm1->second, elm2->second}] == 0) {
        flg = true;
        break;
      }
    }
    if (flg)
      break;
    if (next(elm1)->first != th.front().first)
      ans--;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> t(m);
  vector<int64_t> th(h, 0), tw(w, 0);
  int64_t th_max = 0, tw_max = 0;
  for (auto i = 0; i < m; i++) {
    cin >> t[i].first >> t[i].second;
    t[i].first--;
    t[i].second--;
    th[t[i].first]++;
    tw[t[i].second]++;
    th_max = max(th_max, th[t[i].first]);
    tw_max = max(tw_max, tw[t[i].second]);
  }
  vector<int> ch, cw, c;
  int64_t ans = th_max + tw_max;
  for (auto i = 0; i < h; i++)
    if (th[i] == th_max)
      ch.push_back(i);
  for (auto i = 0; i < w; i++)
    if (tw[i] == tw_max)
      cw.push_back(i);
  for (auto elm1 : ch) {
    bool flg = false;
    for (auto elm2 : cw) {
      auto itr = find(t.begin(), t.end(), make_pair(elm1, elm2));
      if (itr == t.end()) {
        flg = true;
        break;
      }
    }
    if (flg)
      break;
    if (ch.back() == elm1)
      ans--;
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define sz(x) (int)(x.size())
#define FOR(i, L, R) for (int i = L; i <= R; i++)

const int N = 3e5 + 2;

int n, m, cnt_x[N], cnt_y[N];
set<pair<int, int>> given;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  cin >> n >> m;
  int t;
  cin >> t;
  set<int> xs, ys;
  while (t--) {
    int x, y;
    cin >> x >> y;
    given.insert({x, y});
    cnt_x[x]++;
    cnt_y[y]++;
    xs.insert(x);
    ys.insert(y);
  }
  int maxx = 0, maxy = 0;
  vector<int> whichx, whichy;

  FOR(i, 1, N - 1) {
    maxx = max(maxx, cnt_x[i]);
    maxy = max(maxy, cnt_y[i]);
  }
  FOR(i, 1, N - 1) {
    if (cnt_x[i] == maxx) {
      whichx.push_back(i);
    }
    if (cnt_y[i] == maxy) {
      whichy.push_back(i);
    }
  }

  shuffle(whichx.begin(), whichx.end(), rng);
  shuffle(whichy.begin(), whichy.end(), rng);

  for (int x : whichx)
    for (int y : whichy) {
      bool is = given.count({x, y}) > 0;
      if (!is) {
        cout << maxx + maxy << '\\n';
        return 0;
      }
    }
  cout << maxx + maxy - 1;
}


Error: TLE

Fixed submission:

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

#define sz(x) (int)(x.size())
#define FOR(i, L, R) for (int i = L; i <= R; i++)

const int N = 3e5 + 2;

int n, m, cnt_x[N], cnt_y[N];
set<pair<int, int>> given;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  cin >> n >> m;
  int t;
  cin >> t;
  set<int> xs, ys;
  while (t--) {
    int x, y;
    cin >> x >> y;
    given.insert({x, y});
    cnt_x[x]++;
    cnt_y[y]++;
    xs.insert(x);
    ys.insert(y);
  }
  int maxx = 0, maxy = 0;
  set<int> whichx, whichy;

  FOR(i, 1, N - 1) {
    maxx = max(maxx, cnt_x[i]);
    maxy = max(maxy, cnt_y[i]);
  }
  FOR(i, 1, N - 1) {
    if (cnt_x[i] == maxx) {
      whichx.insert(i);
    }
    if (cnt_y[i] == maxy) {
      whichy.insert(i);
    }
  }
  int ans = 0;
  for (int x : whichx)
    for (int y : whichy) {
      int get = cnt_x[x] + cnt_y[y] - (given.count({x, y}) > 0);
      ans = max(ans, get);
    }
  cout << ans;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  int H, W, M;
  std::cin >> H >> W >> M;
  std::map<std::string, int> bomb_pos;
  // std::vector< std::vector< int > > bomb_pos(H);
  std::vector<int> H_bomb_cnt(H);
  std::vector<int> W_bomb_cnt(W);

  for (int i = 0; i < M; i++) {
    int tmp_h, tmp_w;
    std::cin >> tmp_h >> tmp_w;
    tmp_h--;
    tmp_w--;
    H_bomb_cnt[tmp_h]++;
    W_bomb_cnt[tmp_w]++;
    std::ostringstream oss;
    oss << tmp_h << "_" << tmp_w;
    std::string tmp_s = oss.str();
    // bomb_pos[tmp_h].push_back(tmp_w);
    bomb_pos[tmp_s] = 1;
  }

  int H_max = 0;
  std::vector<int> H_maxpos;
  int W_max = 0;
  std::vector<int> W_maxpos;
  for (int i = 0; i < H; i++) {
    if (H_max < H_bomb_cnt[i]) {
      H_maxpos.assign(1, i);
      H_max = H_bomb_cnt[i];
    } else if (H_max == H_bomb_cnt[i]) {
      H_maxpos.push_back(i);
    }
  }
  for (int i = 0; i < W; i++) {
    if (W_max < W_bomb_cnt[i]) {
      W_maxpos.assign(1, i);
      W_max = W_bomb_cnt[i];
    } else if (W_max == W_bomb_cnt[i]) {
      W_maxpos.push_back(i);
    }
  }

  for (int i = 0; i < H_maxpos.size(); i++) {
    for (int j = 0; j < W_maxpos.size(); j++) {
      std::ostringstream oss;
      oss << H_maxpos[i] << "_" << W_maxpos[j];
      std::string tmp_s = oss.str();
      auto itr = bomb_pos.find(tmp_s);
      if (itr == bomb_pos.end()) {
        std::cout << H_max + W_max << std::endl;
        return 0;
      }
    }
  }

  std::cout << H_max + W_max - 1 << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  int H, W, M;
  std::cin >> H >> W >> M;
  std::vector<std::vector<int>> bomb_pos(H);
  std::vector<int> H_bomb_cnt(H);
  std::vector<int> W_bomb_cnt(W);

  for (int i = 0; i < M; i++) {
    int tmp_h, tmp_w;
    std::cin >> tmp_h >> tmp_w;
    H_bomb_cnt[tmp_h - 1]++;
    W_bomb_cnt[tmp_w - 1]++;
    bomb_pos[tmp_h - 1].push_back(tmp_w - 1);
  }

  int H_max = 0;
  std::vector<int> H_maxpos;
  int W_max = 0;
  std::vector<int> W_maxpos;
  for (int i = 0; i < H; i++) {
    if (H_max < H_bomb_cnt[i]) {
      H_maxpos.assign(1, i);
      H_max = H_bomb_cnt[i];
    } else if (H_max == H_bomb_cnt[i]) {
      H_maxpos.push_back(i);
    }
  }
  for (int i = 0; i < W; i++) {
    if (W_max < W_bomb_cnt[i]) {
      W_maxpos.assign(1, i);
      W_max = W_bomb_cnt[i];
    } else if (W_max == W_bomb_cnt[i]) {
      W_maxpos.push_back(i);
    }
  }

  for (int i = 0; i < H_maxpos.size(); i++) {
    for (int j = 0; j < W_maxpos.size(); j++) {
      bool find = false;
      for (int k = 0; k < bomb_pos[H_maxpos[i]].size(); k++) {
        if (bomb_pos[H_maxpos[i]][k] == W_maxpos[j]) {
          find = true;
          break;
        }
      }
      if (!find) {
        std::cout << H_max + W_max << std::endl;
        return 0;
      }
    }
  }

  std::cout << H_max + W_max - 1 << std::endl;

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

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

#define rep(i, a) for (int i = 0; i < (a); i++)

typedef pair<int, int> P;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1000000007;
const double PI = acos(-1);

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  set<pair<int, int>> S;

  vector<vector<int>> Aw(W, vector<int>(2, 0));
  vector<vector<int>> Ah(H, vector<int>(2, 0));
  rep(i, W) { Aw[i][1] = i; }
  rep(i, H) { Ah[i][1] = i; }

  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    S.insert(make_pair(h, w));
    Ah[h][0]++;
    Aw[w][0]++;
  }
  sort(Aw.begin(), Aw.end());
  sort(Ah.begin(), Ah.end());
  ll ans = 0;

  ll wnum = Aw.back()[0];
  ll wint = Aw.back()[1];
  vector<int> wmax;
  int idx = W - 1;
  while (Aw[idx][0] == wnum) {
    wmax.push_back(Aw[idx][1]);
    idx--;
    if (idx < 0)
      break;
  }

  ll hnum = Ah.back()[0];
  ll hint = Ah.back()[1];
  vector<int> hmax;
  idx = H - 1;
  while (Ah[idx][0] == hnum) {
    hmax.push_back(Ah[idx][1]);
    idx--;
    if (idx < 0)
      break;
  }

  int cnt = 0;
  rep(h, hmax.size()) {
    rep(w, wmax.size()) {
      ll tmp = hnum + wnum;
      // cout << hmax[h]+1 << " " << wmax[w]+1 << endl;
      if (S.count(make_pair(hmax[h], wmax[w]))) {
        tmp--;
      }
      ans = max(ans, tmp);
      cnt++;
    }
    if (cnt > 1000000)
      break;
    if (cnt > 1000000)
      break;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

#define rep(i, a) for (int i = 0; i < (a); i++)

typedef pair<int, int> P;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1000000007;
const double PI = acos(-1);

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  set<pair<int, int>> S;

  vector<vector<int>> Aw(W, vector<int>(2, 0));
  vector<vector<int>> Ah(H, vector<int>(2, 0));
  rep(i, W) { Aw[i][1] = i; }
  rep(i, H) { Ah[i][1] = i; }

  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    S.insert(make_pair(h, w));
    Ah[h][0]++;
    Aw[w][0]++;
  }
  sort(Aw.begin(), Aw.end());
  sort(Ah.begin(), Ah.end());
  ll ans = 0;

  ll wnum = Aw.back()[0];
  ll wint = Aw.back()[1];
  vector<int> wmax;
  int idx = W - 1;
  while (Aw[idx][0] == wnum) {
    wmax.push_back(Aw[idx][1]);
    idx--;
    if (idx < 0)
      break;
  }

  ll hnum = Ah.back()[0];
  ll hint = Ah.back()[1];
  vector<int> hmax;
  idx = H - 1;
  while (Ah[idx][0] == hnum) {
    hmax.push_back(Ah[idx][1]);
    idx--;
    if (idx < 0)
      break;
  }

  int cnt = 0;
  rep(h, hmax.size()) {
    rep(w, wmax.size()) {
      ll tmp = hnum + wnum;
      // cout << hmax[h]+1 << " " << wmax[w]+1 << endl;
      if (S.count(make_pair(hmax[h], wmax[w]))) {
        tmp--;
      }
      ans = max(ans, tmp);
    }
    if (cnt > 1000000)
      break;
    if (cnt > 1000000)
      break;
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int main() {
  int t = 1;
  while (t--) {
    int h, w;
    cin >> h >> w;
    int m;
    cin >> m;
    int maxCol = 0, maxRow = 0;
    vector<int> hc(h + 1, 0), wc(w + 1, 0);
    map<pair<int, int>, int> mp;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> y >> x;
      hc[y]++;
      wc[x]++;
      maxCol = max(maxCol, hc[y]);
      maxRow = max(maxRow, wc[x]);
      mp[{y, x}]++;
    }

    vector<int> colsWithMax, rowsWithMax;

    for (int i = 1; i <= h; i++) {
      if (hc[i] == maxCol)
        colsWithMax.push_back(i);
    }

    for (int i = 1; i <= w; i++) {
      if (wc[i] == maxRow)
        rowsWithMax.push_back(i);
    }

    int ans = maxCol + maxRow - 1;

    for (auto i : colsWithMax) {
      for (auto j : rowsWithMax) {
        if (mp.find({i, j}) == mp.end()) {
          ans++;
          goto outer;
        }
      }
    }

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


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main(void) {
  int h, w, m;
  int r[N];
  int c[N];
  int maxRow = 0;
  int maxCol = 0;
  unordered_map<string, int> hash;
  cin >> h >> w >> m;
  cout << h << endl;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    r[x]++;
    c[y]++;
    hash[x + "" + y] = 1;
  }
  for (int i = 1; i <= w; ++i) {
    maxRow = max(r[i], maxRow);
  }
  for (int i = 1; i <= h; ++i) {
    maxCol = max(c[i], maxCol);
  }

  vector<int> cx;
  vector<int> cy;
  for (int i = 1; i <= w; ++i) {
    if (r[i] == maxRow) {
      cx.push_back(i);
    }
  }
  for (int i = 1; i <= h; ++i) {
    if (c[i] == maxCol) {
      cy.push_back(i);
    }
  }
  int ans = maxRow + maxCol - 1;
  for (int x : cx) {
    for (int y : cy) {
      if (!hash.count(x + "" + y)) {
        cout << ans + 1 << endl;
        return 1;
      }
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

int main() {
  fast;
  int t = 1;
  while (t--) {
    int h, w, m;
    cin >> h >> w >> m;

    vector<int> f1(h + 1);
    vector<int> f2(w + 1);
    unordered_map<int, unordered_set<int>> mp2;
    int maxx = 0, maxy = 0;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      mp2[x].insert(y);
      f1[x]++;
      f2[y]++;
      maxx = max(maxx, f1[x]);
      maxy = max(maxy, f2[y]);
    }
    int ans = maxx + maxy - 1;
    vector<int> v1, v2;
    for (int i = 1; i <= h; i++) {
      if (f1[i] == maxx)
        v1.push_back(i);
    }
    for (int i = 1; i <= w; i++) {
      if (f2[i] == maxy)
        v2.push_back(i);
    }
    bool f = 0;
    for (auto i : v1) {
      for (auto j : v2) {
        // cout << i << " " << j << "\\n";
        if (mp2[i].find(j) == mp2[i].end()) {
          ans++;
          f = 1;
          break;
        }
      }
      if (f)
        break;
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

int main() {
  fast;
  int t = 1;
  while (t--) {
    int h, w, m;
    cin >> h >> w >> m;

    unordered_map<int, int> mp;
    unordered_map<int, int> mp1;
    unordered_map<int, unordered_set<int>> mp2;
    int maxx = 0, maxy = 0;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      mp2[x].insert(y);
      mp[x]++;
      mp1[y]++;
      maxx = max(maxx, mp[x]);
      maxy = max(maxy, mp1[y]);
    }

    vector<int> f1, f2;
    for (auto i : mp) {
      if (i.ss == maxx)
        f1.push_back(i.ff);
    }
    for (auto i : mp1) {
      if (i.ss == maxy)
        f2.push_back(i.ff);
    }
    int maxnum = 0;
    for (auto i : f1) {
      for (auto j : f2) {
        // cout << i << " " << j << "\\n";
        if (mp2[i].find(j) != mp2[i].end()) {
          maxnum = max(maxnum, (mp[i] + mp1[j] - 1));
          // cout << maxnum << " ";
        } else {

          maxnum = max(maxnum, (mp[i] + mp1[j]));
        }
      }
    }
    cout << maxnum << "\\n";
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> v;

  int r[h], c[w];
  memset(r, 0, sizeof(r));
  memset(c, 0, sizeof(c));

  while (m--) {
    int i, j;
    cin >> i >> j;
    i--;
    j--;
    v.push_back({i, j});
    r[i]++;
    c[j]++;
  }

  int mr = 0, mc = 0;
  for (auto e : r) {
    mr = max(mr, e);
  }
  for (auto e : c) {
    mc = max(mc, e);
  }

  set<int> sr, sc;
  for (int i = 0; i < h; i++) {
    if (r[i] == mr)
      sr.insert(i);
  }
  for (int j = 0; j < w; j++) {
    if (c[j] == mc)
      sc.insert(j);
  }

  int cnt = sr.size() * sc.size();

  for (auto p : v) {
    int i = p.first, j = p.second;
    if (sr.count(i) and sc.count(j)) {
      cnt--;
    }
  }

  if (cnt > 0) {
    cout << mr + mc << endl;
  } else {
    cout << mr + mc - 1 << endl;
  }

  return 0;
}

/*

..#
###
.#.

*/


Error: 0

Fixed submission:

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int h, w, m;
  cin >> h >> w >> m;
  int a[h][w], b[h][w];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  while (m--) {
    int i, j;
    cin >> i >> j;
    i--;
    j--;
    a[i][j] = 1;
  }

  int r[h], c[w];
  for (int i = 0; i < h; i++) {
    int sum = 0;
    for (int j = 0; j < w; j++) {
      sum += a[i][j];
    }
    r[i] = sum;
  }

  for (int j = 0; j < w; j++) {
    int sum = 0;
    for (int i = 0; i < h; i++) {
      sum += a[i][j];
    }
    c[j] = sum;
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      b[i][j] = r[i] + c[j] - a[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, b[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}
/*

..#
###
.#.

*/
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int H, W, M, hbuf, wbuf;
  cin >> H >> W >> M;
  vector<int> TargetH(H, 0);
  vector<int> TargetW(W, 0);
  set<pair<int, int>> Targets;
  vector<int> maxRows;
  vector<int> maxColumns;
  for (int i = 0; i < M; i++) {
    cin >> hbuf >> wbuf;
    hbuf--;
    wbuf--;
    TargetH[hbuf]++;
    TargetW[wbuf]++;
    Targets.insert(pair<int, int>(hbuf, wbuf));
  }
  int maxH = 0;
  int maxW = 0;
  for (int i = 1; i < H; i++)
    if (TargetH[maxH] < TargetH[i])
      maxH = i;
  for (int i = 1; i < W; i++)
    if (TargetW[maxW] < TargetW[i])
      maxW = i;
  for (int i = 0; i < H; i++)
    if (TargetH[maxH] == TargetH[i])
      maxRows.push_back(i);
  for (int i = 0; i < W; i++)
    if (TargetW[maxW] == TargetW[i])
      maxColumns.push_back(i);
  int intBombatTarget = -1;
  bool breakable = false;
  if (maxColumns.size() * maxRows.size() <= M) {
    for (int row : maxRows) {
      for (int column : maxColumns) {
        if (Targets.find(pair<int, int>(row, column)) == Targets.end()) {
          intBombatTarget = 0;
          breakable = true;
          break;
        } else {
          Targets.erase(pair<int, int>(row, column));
        }
      }
      if (breakable)
        break;
    }
  } else
    intBombatTarget = 0;
  cout << TargetH[maxH] + TargetW[maxW] + intBombatTarget << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int H, W, M, hbuf, wbuf;
  cin >> H >> W >> M;
  vector<int> TargetH(H, 0);
  vector<int> TargetW(W, 0);
  vector<pair<int, int>> Targets;
  vector<int> maxRows;
  vector<int> maxColumns;
  for (int i = 0; i < M; i++) {
    cin >> hbuf >> wbuf;
    hbuf--;
    wbuf--;
    TargetH[hbuf]++;
    TargetW[wbuf]++;
    Targets.push_back(pair<int, int>(hbuf, wbuf));
  }
  sort(Targets.begin(), Targets.end());
  int maxH = 0;
  int maxW = 0;
  for (int i = 1; i < H; i++)
    if (TargetH[maxH] < TargetH[i])
      maxH = i;
  for (int i = 1; i < W; i++)
    if (TargetW[maxW] < TargetW[i])
      maxW = i;
  for (int i = 0; i < H; i++)
    if (TargetH[maxH] == TargetH[i])
      maxRows.push_back(i);
  for (int i = 0; i < W; i++)
    if (TargetW[maxW] == TargetW[i])
      maxColumns.push_back(i);
  int intBombatTarget = -1;
  bool breakable = false;
  if (maxColumns.size() * maxRows.size() <= M) {
    for (int row : maxRows) {
      for (int column : maxColumns) {
        if (find(Targets.begin(), Targets.end(), pair<int, int>(row, column)) ==
            Targets.end()) {
          intBombatTarget = 0;
          breakable = true;
          break;
        }
      }
      if (breakable)
        break;
    }
  } else
    intBombatTarget = 0;
  cout << TargetH[maxH] + TargetW[maxW] + intBombatTarget << endl;
  return 0;
}