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

#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define md 1000000007

using namespace std;

int solve() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<long long, long long>> v;
  vector<long long> mpr[h + 10], mpc[w + 10];
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    v.push_back({x, y});
    mpr[x].push_back(y);
    mpc[y].push_back(x);
  }
  int r = 0;
  for (int i = 0; i <= h; i++) {
    if (mpr[i].size() > mpr[r].size())
      r = i;
  }
  // sort(mpr[r].begin(), mpr[r].end());
  vector<long long> vis(w + 10);
  for (auto it : mpr[r])
    vis[it] = 1;
  ll mx = 0;
  for (int i = 0; i <= w; i++) {
    ll ct = mpr[r].size() + mpc[i].size();
    if (vis[i])
      ct--;
    mx = max(mx, ct);
  }
  vis.clear();
  r = 0;
  for (int i = 0; i <= w; i++) {
    if (mpc[i].size() > mpc[r].size())
      r = i;
  }
  vis.assign(h + 10, 0);
  for (auto it : mpc[r])
    vis[it] = 1;

  for (int i = 0; i <= h; i++) {
    ll ct = mpr[i].size() + mpc[r].size();
    if (vis[i])
      ct--;
    mx = max(mx, ct);
  }
  cout << mx << endl;

  return 0;
}

int main() {
  fast;
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define md 1000000007

using namespace std;

int solve() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<long long, long long>> v;
  vector<long long> mpr[h + 10], mpc[w + 10];
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    v.push_back({x, y});
    mpr[x].push_back(y);
    mpc[y].push_back(x);
  }
  int r = 0;
  for (int i = 0; i <= h; i++) {
    if (mpr[i].size() > mpr[r].size())
      r = i;
  }
  // sort(mpr[r].begin(), mpr[r].end());
  vector<long long> vis(w + 10);
  for (auto it : mpr[r])
    vis[it] = 1;
  ll mx = 0;
  for (int i = 0; i <= w; i++) {
    ll ct = mpr[r].size() + mpc[i].size();
    if (vis[i])
      ct--;
    mx = max(mx, ct);
  }
  vis.clear();
  r = 0;
  for (int i = 0; i <= w; i++) {
    if (mpc[i].size() > mpc[r].size())
      r = i;
  }
  vis.assign(h + 10, 0);
  for (auto it : mpr[r])
    vis[it] = 1;

  for (int i = 0; i <= w; i++) {
    ll ct = mpr[i].size() + mpc[r].size();
    if (vis[i])
      ct--;
    mx = max(mx, ct);
  }
  cout << mx << endl;

  return 0;
}

int main() {
  fast;
  solve();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  int h, w, m, x, y;
  cin >> h >> w >> m;
  map<int, int> r, c;
  map<pair<int, int>, int> grid;
  pair<int, int> p;
  while (m--) {
    cin >> x >> y;
    r[x]++;
    c[y]++;
    p.first = x;
    p.second = y;
    grid[p] = 1;
  }
  vector<int> dx, dy;
  map<int, int>::iterator it;
  ll mr = 0, mc = 0;
  for (it = r.begin(); it != r.end(); it++) {
    mr = max(mr, (ll)it->second);
  }
  for (it = c.begin(); it != c.end(); it++) {
    mc = max(mc, (ll)it->second);
  }
  for (it = r.begin(); it != r.end(); it++) {
    if (it->second == mr) {
      dx.push_back(it->first);
    }
  }
  for (it = c.begin(); it != c.end(); it++) {
    if (it->second == mc) {
      dy.push_back(it->first);
    }
  }
  ll ans = mr + mc - 1;
  for (int i = 0; i < dx.size(); i++) {
    for (int j = 0; j < dy.size(); j++) {
      p.first = dx[i];
      p.second = dy[j];
      if (grid[p] == 0) {
        cout << ans + 1;
        return 0;
      }
    }
  }
  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  int h, w, m, x, y;
  cin >> h >> w >> m;
  map<int, int> r, c;
  pair<int, int> p;
  int grid[h + 1][w + 1];
  memset(grid, 0, sizeof grid);
  while (m--) {
    cin >> x >> y;
    r[x]++;
    c[y]++;
    grid[x][y] = 1;
  }
  vector<int> dx, dy;
  map<int, int>::iterator it;
  ll mr = 0, mc = 0;
  for (it = r.begin(); it != r.end(); it++) {
    mr = max(mr, (ll)it->second);
  }
  for (it = c.begin(); it != c.end(); it++) {
    mc = max(mc, (ll)it->second);
  }
  for (it = r.begin(); it != r.end(); it++) {
    if (it->second == mr) {
      dx.push_back(it->first);
    }
  }
  for (it = c.begin(); it != c.end(); it++) {
    if (it->second == mc) {
      dy.push_back(it->first);
    }
  }
  ll ans = mr + mc - 1;
  for (int i = 0; i < dx.size(); i++) {
    for (int j = 0; j < dy.size(); j++) {
      if (grid[dx[i]][dy[j]] == 0) {
        cout << ans + 1;
        return 0;
      }
    }
  }
  cout << ans;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
int H, W, m, x, y, h[300005], w[300005], mh = -1, mw = -1, ans, b = 0;
map<int, int> ht;
map<int, int> wt;
map<pair<int, int>, bool> pt;
vector<int> mah;
vector<int> maw;
int main() {
  scanf("%d%d%d", &H, &W, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &h[i], &w[i]);
    pt[{h[i], w[i]}] = 1;
    ht[h[i]]++;
    wt[w[i]]++;
    if (ht[h[i]] > mh)
      mh = ht[h[i]];
    if (wt[w[i]] > mw)
      mw = wt[w[i]];
  }
  for (int i = 1; i <= H; i++)
    if (ht[i] == mh)
      mah.push_back(i);
  for (int i = 1; i <= W; i++)
    if (wt[i] == mw)
      maw.push_back(i);
  ans = mh + mw - 1;
  for (int i = 0; i < mah.size(); i++) {
    for (int j = 0; j < maw.size(); j++) {
      if (pt[{mah[i], maw[j]}] == 0) {
        ans = mh + mw;
        b = 1;
        break;
      }
    }
    if (b)
      break;
  }
  printf("%d", ans);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
int H, W, m, x, y, h[300005], w[300005], mh = -1, mw = -1, ans;
map<int, int> ht;
map<int, int> wt;
map<pair<int, int>, bool> pt;
vector<int> mah;
vector<int> maw;
int main() {
  scanf("%d%d%d", &H, &W, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &h[i], &w[i]);
    pt[{h[i], w[i]}] = 1;
    ht[h[i]]++;
    wt[w[i]]++;
    if (ht[h[i]] > mh)
      mh = ht[h[i]];
    if (wt[w[i]] > mw)
      mw = wt[w[i]];
  }
  for (int i = 1; i <= H; i++)
    if (ht[i] == mh)
      mah.push_back(i);
  for (int i = 1; i <= W; i++)
    if (wt[i] == mw)
      maw.push_back(i);
  ans = mh + mw - 1;
  for (int i = 0; i < mah.size(); i++)
    for (int j = 0; j < maw.size(); j++) {
      if (pt[{mah[i], maw[j]}] == 0) {
        ans = mh + mw;
      }
    }
  printf("%d", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;

#define lli long long int
int n, m, k, x, y;

int main() {
  cin >> n >> m >> k;

  map<int, int> r, c;
  map<int, set<int>> v;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    v[x].insert(y);
    if (r.count(x))
      r[x]++;
    else
      r[x] = 1;

    if (c.count(y))
      c[y]++;
    else
      c[y] = 1;
  }

  int mr, mc, mrc = 0, mcc = 0;

  set<int> tr, tc;
  for (auto x : r) {
    if (x.second > mrc) {
      mrc = x.second;
    }
  }

  for (auto x : r) {
    if (mrc == x.second)
      tr.insert(x.first);
  }

  for (auto x : c) {
    if (x.second > mcc) {
      mcc = x.second;
    }
  }

  for (auto x : c) {
    if (mcc == x.second)
      tc.insert(x.first);
  }

  int s = mrc + mcc, f = 0;
  for (auto x : v) {
    if (tr.find(x.first) != tr.end()) {
      set<int> rem;
      for (auto y : x.second) {
        if (tc.find(y) != tc.end()) {
          rem.insert(y);
        }
      }
      if (rem.size() != tc.size()) {
        f = 1;
        break;
      }
    }
  }

  if (f == 1)
    cout << s << "\\n";
  else
    cout << s - 1 << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;

#define lli long long int
int n, m, k, x, y;

int main() {
  cin >> n >> m >> k;

  map<int, int> r, c;
  map<int, set<int>> v;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    v[y].insert(x);
    if (r.count(x))
      r[x]++;
    else
      r[x] = 1;

    if (c.count(y))
      c[y]++;
    else
      c[y] = 1;
  }

  int mr, mc, mrc = 0, mcc = 0;

  vector<int> tr, tc;
  for (auto x : r) {
    if (x.second > mrc) {
      mrc = x.second;
    }
  }

  for (auto x : r) {
    if (mrc == x.second)
      tr.push_back(x.first);
  }

  for (auto x : c) {
    if (x.second > mcc) {
      mcc = x.second;
    }
  }

  for (auto x : c) {
    if (mcc == x.second)
      tc.push_back(x.first);
  }

  int s = 0;
  for (auto x : tr) {
    for (auto y : tc) {
      // cout<<x<<" "<<y<<" ";
      // cout<<r[x]<<" "<<c[y]<<"\\n";
      if (v[y].find(x) != v[y].end())
        s = max(s, r[x] + c[y] - 1);
      else
        s = max(s, r[x] + c[y]);
      // cout<<s<<"\\n";
    }
  }

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

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  set<P> points;
  rep(i, M) {
    cin >> h.at(i) >> w.at(i);
    points.insert({h.at(i), w.at(i)});
  }
  map<int, int> hCount, wCount;
  rep(i, M) {
    hCount[h.at(i)]++;
    wCount[w.at(i)]++;
  }

  int hMax = 0, wMax = 0;
  vector<int> hm, wm;
  for (auto hc : hCount) {
    if (hMax < hc.second) {
      hm.clear();
      hm.push_back(hc.first);
    }
    if (hMax == hc.second)
      hm.push_back(hc.first);
    hMax = max(hMax, hc.second);
  }
  for (auto wc : wCount) {
    if (wMax < wc.second) {
      wm.clear();
      wm.push_back(wc.first);
    }
    if (wMax == wc.second)
      wm.push_back(wc.first);
    wMax = max(wMax, wc.second);
  }
  int ans = hMax + wMax - 1;
  for (auto hi : hm) {
    for (auto wi : wm) {
      if (points.find({hi, wi}) == points.end()) {
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  rep(i, M) cin >> h.at(i) >> w.at(i);
  map<int, int> hCount, wCount;
  rep(i, M) {
    hCount[h.at(i)]++;
    wCount[w.at(i)]++;
  }

  int hMax = 0, wMax = 0;
  vector<int> hm, wm;
  for (auto hc : hCount) {
    if (hMax < hc.second) {
      hm.clear();
      hm.push_back(hc.first);
    }
    if (hMax == hc.second)
      hm.push_back(hc.first);
    hMax = max(hMax, hc.second);
  }
  for (auto wc : wCount) {
    if (wMax < wc.second) {
      wm.clear();
      wm.push_back(wc.first);
    }
    if (wMax == wc.second)
      wm.push_back(wc.first);
    wMax = max(wMax, wc.second);
  }
  int ans = hMax + wMax;
  int overlap = 0;
  for (auto hi : hm) {
    for (auto wi : wm) {
      rep(i, M) {
        if (h.at(i) == hi && w.at(i) == wi)
          overlap++;
      }
    }
  }
  if (overlap == hm.size() * wm.size())
    ans--;
  cout << ans << endl;
  return 0;
}
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;
  int num[w], numh[h];
  for (int i = 0; i < w; i++)
    num[i] = 0;
  for (int i = 0; i < h; i++)
    numh[i] = 0;
  int maxw = 0;
  int maxh = 0;
  set<pair<int, int>> mm;
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    num[wi]++;
    numh[hi]++;
    maxw = max(maxw, num[wi]);
    mm.insert(make_pair(hi, wi));
    maxh = max(maxh, numh[hi]);
  }
  int res = maxh + maxw - 1;
  vector<int> hm;
  for (int i = 0; i < h; i++) {
    if (numh[i] == maxh)
      hm.push_back(i);
  }
  int ttt = hm.size();
  for (int i = 0; i < w; i++) {
    if (num[i] == maxw) {
      for (int j = 0; j < ttt; j++) {
        if (mm.count(make_pair(hm[j], i)) == 0) {
          cout << res + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int h, w, m;
  cin >> h >> w >> m;
  int num[w], numh[h];
  for (int i = 0; i < w; i++)
    num[i] = 0;
  for (int i = 0; i < h; i++)
    numh[i] = 0;
  int maxw = 0;
  int maxh = 0;
  vector<int> mm[h];
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    num[wi - 1]++;
    numh[hi - 1]++;
    maxw = max(maxw, num[wi - 1]);
    mm[hi - 1].push_back(wi);
    maxh = max(maxh, numh[hi - 1]);
  }
  int res = maxh + maxw - 1;
  vector<int> hm;
  for (int i = 0; i < h; i++) {
    if (numh[i] == maxh)
      hm.push_back(i);
  }
  int ttt = hm.size();
  for (int i = 0; i < w; i++) {
    if (num[i] == maxw) {
      for (int j = 0; j < ttt; j++) {
        int k;
        for (k = 0; k < maxh; k++) {
          if (i + 1 == mm[hm[j]][k])
            break;
        }
        if (k == maxh) {
          cout << res + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << res << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// #define int long long
#define deb(x) cout << #x << " = " << x << endl
template <typename T> vector<T> readVector(int n) {
  vector<T> res(n);
  for (int i = 0; i < n; i++)
    cin >> res[i];
  return res;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hor(3e5 + 5, 0), ver(3e5 + 5, 0);

  set<pair<int, int>> st;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    st.insert({x, y});
    hor[x]++;
    ver[y]++;
  }
  /// now i have hor and ver
  vector<int> mx_hor, mx_ver;
  int mx_h = 0, mx_v = 0;
  for (int i = 0; i < hor.size(); i++) {
    if (hor[i] > mx_h) {
      mx_hor.clear();
      mx_hor.push_back(i);
      mx_h = hor[i];
    } else if (hor[i] == mx_h) {
      mx_hor.push_back(i);
    }
  }
  for (int i = 0; i < ver.size(); i++) {
    if (ver[i] > mx_v) {
      mx_ver.clear();
      mx_ver.push_back(i);
      mx_v = ver[i];
    } else if (ver[i] == mx_v) {
      mx_ver.push_back(i);
    }
  }
  int ans = mx_h + mx_v;
  int one = 1;
  for (auto u : mx_hor) {
    for (auto v : mx_ver) {
      if (st.find({u, v}) == st.end()) {
        one = 0;
        break;
      }
    }
    if (one == 0)
      break;
  }
  cout << ans - one;
  return 0;
}


Error: TLE

Fixed submission:

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

#define int long long
#define deb(x) cout << #x << " = " << x << endl
template <typename T> vector<T> readVector(int n) {
  vector<T> res(n);
  for (int i = 0; i < n; i++)
    cin >> res[i];
  return res;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hor(3e5 + 5, 0), ver(3e5 + 5, 0);
  /// vector<vector<int>> mark(h+5, vector<int> (w+5, 0));

  set<pair<int, int>> st;

  for (long long i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    /// mark[x][y]++;
    st.insert({x, y});
    hor[x]++;
    ver[y]++;
  }
  int ans = 0;
  int mx = 0;
  for (int i = 1; i <= h; i++) {
    if (hor[i] < mx)
      continue;
    for (int j = 1; j <= w; j++) {
      mx = max(mx, hor[i]);
      int v = 0;
      if (st.find({i, j}) != st.end())
        v = 1LL;
      ans = max(ans, (hor[i] + ver[j] - v));
    }
  }
  cout << ans;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
V<int> dx = {-1, 1, 0, 0, -1, -1, 1, 1};
V<int> dy = {0, 0, -1, 1, -1, 1, -1, 1};

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  V<int> tate(w), yoko(h);
  V<P> p(m);
  rep(i, m) {
    int H, W;
    cin >> H >> W;
    H--;
    W--;
    tate[W]++;
    yoko[H]++;
    p[i] = {W, H};
  }
  int mx1 = 0, mx2 = 0;
  rep(i, w) chmax(mx1, tate[i]);
  rep(i, h) chmax(mx2, yoko[i]);
  set<int> mx_tate, mx_yoko;
  rep(i, w) {
    if (tate[i] == mx1)
      mx_tate.insert(i);
  }
  rep(i, h) {
    if (yoko[i] == mx2)
      mx_yoko.insert(i);
  }
  int ans = mx1 + mx2 - 1;
  ll c = (ll)mx_tate.size() *
         mx_yoko.size(); // 一つでも爆破対象じゃないところがあったらmx1+mx2
  ll cnt = 0; // 爆破対象かつ、maxの行と列に属するものの数
  rep(i, m) {
    int x = p[i].first, y = p[i].second;
    if (mx_tate.count(x) && mx_yoko.count(y))
      cnt++;
  }
  if (c > cnt)
    ans = mx1 + mx2;
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
V<int> dx = {-1, 1, 0, 0, -1, -1, 1, 1};
V<int> dy = {0, 0, -1, 1, -1, 1, -1, 1};

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  V<ll> tate(w, 0), yoko(h, 0);
  map<P, int> mp;
  V<P> p(m);
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--;
    x--;
    yoko[y]++;
    tate[x]++;
    mp[{x, y}]++;
    p[i] = {x, y};
  }
  int mx1 = 0, mx2 = 0;
  int p1 = 0, p2 = 0;
  rep(i, h) {
    if (yoko[i] > mx1) {
      mx1 = yoko[i];
      p1 = i;
    } else if (yoko[i] > mx2) {
      mx2 = yoko[i];
      p2 = i;
    }
  }
  ll ans = 0;
  rep(i, w) {
    int x = p[i].first, y = p[i].second;
    if (mp[{x, p1}] > 0 && mp[{x, p2}] > 0) {
      chmax(ans, tate[i] + mx1 - 1);
      chmax(ans, tate[i] + mx2 - 1);
    } else if (mp[{x, p1}] > 0) {
      chmax(ans, tate[i] + mx1 - 1);
      chmax(ans, tate[i] + mx2);
    } else {
      chmax(ans, tate[i] + mx1);
    }
  }
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
long long int H, W;
long long int id(long long int i, long long int j) { return i * W + j; }
int main() {
  int flag;
  long long int M, h, w, ans = 0, sum;
  cin >> H >> W >> M;
  P row[H], col[W];
  map<long long int, int> bomb;

  for (int i = 0; i < H; i++) {
    row[i].second = i;
    row[i].first = 0;
  }
  for (int i = 0; i < W; i++) {
    col[i].second = i;
    col[i].first = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> h >> w;
    h--;
    w--;
    bomb[id(h, w)] = 1;
    row[h].first++;
    col[w].first++;
  }
  sort(row, row + H);
  sort(col, col + W);
  for (int i = H - 1; i >= 0; i--) {
    for (int j = W - 1; j >= 0; j--) {
      flag = bomb[id(row[i].second, col[j].second)];
      sum = row[i].first + col[j].first;
      sum -= flag;
      if (col[j].first < col[W - 1].first)
        break;
      else
        ans = max(sum, ans);
      if (!flag)
        break;
    }
    if (row[i].first < row[H - 1].first)
      break;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
long long int H, W;
long long int id(long long int i, long long int j) { return i * W + j; }
int main() {
  long long int M, h, w, ans = 0, sum;
  cin >> H >> W >> M;
  P row[H], col[W];
  map<long long int, int> bomb;

  for (int i = 0; i < H; i++) {
    row[i].second = i;
    row[i].first = 0;
  }
  for (int i = 0; i < W; i++) {
    col[i].second = i;
    col[i].first = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> h >> w;
    h--;
    w--;
    bomb[id(h, w)] = 1;
    row[h].first++;
    col[w].first++;
  }
  sort(row, row + H);
  sort(col, col + W);
  for (int i = H - 1; i >= 0; i--) {
    for (int j = W - 1; j >= 0; j--) {
      sum = row[i].first + col[j].first;
      sum -= bomb[id(row[i].second, col[j].second)];
      if (col[j].first < col[W - 1].first)
        break;
      else
        ans = max(sum, ans);
    }
    if (row[i].first < row[H - 1].first)
      break;
  }
  cout << ans;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#define ll long long
#define inf 100005
#define mod 1000000007
#define pb push_back
using namespace std;

vector<vector<ll>> g(inf);
vector<ll> indgree(inf);
vector<ll> dist(inf);
bool visted[inf];

int main() {
  ll h, w, m, a, b, temp1, temp2;
  cin >> h >> w >> m;

  vector<ll> rw(h + 1);
  vector<ll> cols(w + 1);
  map<pair<ll, ll>, ll> mymap;
  for (ll i = 0; i < m; i++) {
    cin >> a >> b;
    mymap[make_pair(a, b)] = 1;

    rw[a]++;
    cols[b]++;
  }

  a = -1;
  b = -1;

  for (ll i = 1; i <= h; i++) {
    if (a < rw[i]) {
      a = rw[i];
    }
  }

  vector<ll> c, d;
  for (ll i = 1; i <= w; i++) {
    if (b < cols[i]) {
      b = cols[i];
    }
  }

  for (ll i = 1; i <= h; i++) {
    if (rw[i] == a) {
      d.pb(i);
    }
  }

  for (ll i = 1; i <= w; i++) {
    if (cols[i] == b) {
      c.pb(i);
    }
  }

  ll flag = 0;

  for (ll i = 0; i < d.size(); i++) {
    for (ll j = 0; j < c.size(); j++) {
      if (mymap[make_pair(d[i], c[j])] == 0) {
        flag = 1;
        break;
      }
    }

    if (flag == 1) {
      break;
    }
  }

  if (flag == 1) {
    cout << a + b << endl;
  } else {
    cout << (a + b - 1) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
#define ll long long
#define inf 100005
#define mod 1000000007
#define pb push_back
using namespace std;

vector<vector<ll>> g(inf);
vector<ll> indgree(inf);
vector<ll> dist(inf);
bool visted[inf];

int main() {
  ll h, w, m, a, b, temp1, temp2;
  cin >> h >> w >> m;

  vector<ll> rw(h + 1);
  vector<ll> cols(w + 1);
  vector<vector<ll>> grid(h + 1, vector<ll>(w + 1));
  for (ll i = 0; i < m; i++) {
    cin >> a >> b;
    grid[a][b]++;

    rw[a]++;
    cols[b]++;
  }

  a = -1;
  b = -1;

  for (ll i = 1; i <= h; i++) {
    if (a < rw[i]) {
      a = rw[i];
    }
  }

  vector<ll> c, d;
  for (ll i = 1; i <= w; i++) {
    if (b < cols[i]) {
      b = cols[i];
    }
  }

  for (ll i = 1; i <= h; i++) {
    if (rw[i] == a) {
      d.pb(i);
    }
  }

  for (ll i = 1; i <= w; i++) {
    if (cols[i] == b) {
      c.pb(i);
    }
  }

  ll flag = 0;

  for (ll i = 0; i < d.size(); i++) {
    for (ll j = 0; j < c.size(); j++) {
      if (grid[d[i]][c[j]] == 0) {
        flag = 1;
        break;
      }
    }

    if (flag == 1) {
      break;
    }
  }

  if (flag == 1) {
    cout << a + b << endl;
  } else {
    cout << (a + b - 1) << endl;
  }

  return 0;
}