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

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

#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define erep(i, j, n) for (int i = (j); i <= (n); i++)
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

int H, N;
vi fie;
vvi dp;

int dfs(int h, int state) {
  if (h == H)
    return 0;
  if (dp[h][state] != -1)
    return dp[h][state];

  int ans = dfs(h + 1, fie[h]);

  rep(i, 0, 3) {
    if ((state >> i) & 3)
      continue;
    if ((fie[h] >> i) & 3)
      continue;
    ans = max(ans, dfs(h + 1, fie[h] | (3 << i)) + 1);
  }

  if (state == 0 && fie[h] == 0) {
    ans = max(ans, dfs(h + 1, (1 << 4) - 1) + 2);
  }

  return dp[h][state] = ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> H >> N;
  fie.resize(H);
  dp.resize(H, vi((1 << 4), -1));
  rep(i, 0, N) {
    int x, y;
    cin >> x >> y;
    fie[y] |= (1 << x);
  }

  cout << dfs(1, fie[0]) << endl;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define rep2(i, j, n) for (int i = (j); i <= (n); i++)
#define all(i) i.begin(), i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int dx[] = {1, 0, 1, 0};
int dy[] = {0, 1, 1, 0};
int main() {
  int H, N;
  cin >> H >> N;
  vector<vector<char>> ship(H, vector<char>(4, '.'));

  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ship[x][y] = '#';
  }

  int A = 0;
  int B = 0;

  for (int i = 0; i < H;) {
    bool can = true;
    for (int j = 0; j < 4; j++) {
      if (ship[i + dy[j]][0 + dx[j]] == '#' || i + dy[j] >= H) {
        can = false;
      }
    }
    if (can) {
      i += 2;
      A++;
    } else
      i++;
  }

  for (int i = 0; i < H;) {
    bool can = true;
    for (int j = 0; j < 4; j++) {
      if (ship[i + dy[j]][3 + dx[j]] == '#' || i + dy[j] >= H) {
        can = false;
      }
    }
    if (can) {
      i += 2;
      A++;
    } else
      i++;
  }

  for (int i = 0; i < H;) {
    bool can = true;
    for (int j = 0; j < 4; j++) {
      if (ship[i + dy[j]][2 + dx[j]] == '#' || i + dy[j] >= H) {
        can = false;
      }
    }
    if (can) {
      i += 2;
      B++;
    } else
      i++;
  }

  cout << max(A, B) << endl;
}
Problem p00359 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int, int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
//
struct poi {
  int X;
  int Y;
  int Z;
  bool operator<(const poi &R) const {
    return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
  }
};
//
//
int main() {
  int W, H, N;
  VP V;
  cin >> W >> H >> N;
  FOR(i, 0, N) {
    int X, Y;
    cin >> X >> Y;
    V.PB(MA(X, Y));
  }
  sort(V.begin(), V.end());
  if (N == 1) {
    cout << min(V[0].FI, V[0].SE) << endl;
    return 0;
  }
  VP mid;
  int now = 0;
  while (now < N - 1) {
    while (now < N - 1 && V[now].FI == V[now + 1].FI) {
      now++;
    }
    mid.PB(V[now]);
    now++;
    if (now == N - 1) {
      mid.PB(V[now]);
    }
  }
  VP ans;
  ans.PB(mid.back());
  ROF(i, 0, (int)mid.size()) {
    if (mid[i].SE > ans.back().SE) {
      ans.PB(mid[i]);
    }
  }
  reverse(ans.begin(), ans.end());
  int a = min(ans[0].SE, ans.back().FI);
  FOR(i, 0, (int)ans.size() - 1) { a = min(a, ans[i].FI + ans[i + 1].SE); }
  cout << a << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int, int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
//
struct poi {
  int X;
  int Y;
  int Z;
  bool operator<(const poi &R) const {
    return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
  }
};
//
//
int main() {
  int W, H, N;
  VP V;
  cin >> W >> H >> N;
  FOR(i, 0, N) {
    int X, Y;
    cin >> X >> Y;
    V.PB(MA(X, Y));
  }
  sort(V.begin(), V.end());
  VP mid;
  int now = 0;
  while (now < N - 1) {
    while (now < N - 1 && V[now].FI == V[now + 1].FI) {
      now++;
    }
    mid.PB(V[now]);
    now++;
    if (now == N - 1) {
      mid.PB(V[now]);
    }
  }
  VP ans;
  ans.PB(mid.back());
  ROF(i, 0, (int)mid.size()) {
    if (mid[i].SE > ans.back().SE) {
      ans.PB(mid[i]);
    }
  }
  reverse(ans.begin(), ans.end());
  int a = min(ans[0].SE, ans.back().FI);
  FOR(i, 0, (int)ans.size() - 1) { a = min(a, ans[i].FI + ans[i + 1].SE); }
  cout << a << endl;
  return 0;
}
Problem p00359 (C++) — buggy submission, verdict: Runtime Error

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

const int inf = 1001001001;

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

  vector<int> a(h + 2, 0);

  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;

    a[y] = max(a[y], x);
  }

  int ans = inf;
  for (int i = h; i >= 0; --i) {
    ans = min(ans, i + a[i + 1]);
    a[i] = max(a[i], a[i + 1]);
  }

  cout << ans << endl;
}

Error: -6
double free or corruption (out)


Fixed submission:

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

const int inf = 1001001001;

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

  vector<int> a(h + 1, 0);

  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;

    a[y] = max(a[y], x);
  }

  int ans = inf;
  for (int i = h; i >= 0; --i) {
    ans = min(ans, i + a[i]);
    a[i - 1] = max(a[i], a[i - 1]);
  }

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

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

int wh[100001] = {};

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;
  int at_most_w = 0, at_most_h = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    wh[y] = max(wh[y], x);
    at_most_w = max(x, at_most_w);
    at_most_h = max(y, at_most_h);
  }

  int x_position, y_position, MIN;
  MIN = wh[h - 1] + (h - 1);
  x_position = wh[h - 1];
  y_position = h - 1;

  for (int i = 0; i < h - 1; i++) {
    y_position--;
    int a = x_position, b = y_position;
    MIN = min(MIN, a + b);

    if (a < wh[b]) {
      x_position = wh[y_position];
      int a = x_position, b = y_position;

      MIN = min(MIN, a + b);
    }
  }

  cout << min(MIN, min(at_most_w, at_most_h)) << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int wh[10001] = {};

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;
  int at_most_w = 0, at_most_h = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    wh[y] = max(wh[y], x);
    at_most_w = max(x, at_most_w);
    at_most_h = max(y, at_most_h);
  }

  int x_position, y_position, MIN;
  MIN = wh[h - 1] + (h - 1);
  x_position = wh[h - 1];
  y_position = h - 1;

  for (int i = 0; i < h - 1; i++) {
    y_position--;
    int a = x_position, b = y_position;
    MIN = min(MIN, a + b);

    if (a < wh[b]) {
      x_position = wh[y_position];
      int a = x_position, b = y_position;

      MIN = min(MIN, a + b);
    }
  }

  cout << min(MIN, min(at_most_w, at_most_h)) << endl;

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

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

int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &n, &n);
  vector<pair<int, int>> v;
  multiset<int> se;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    v.push_back(make_pair(a, b));
    se.insert(b);
  }
  sort(v.begin(), v.end());
  int r = min(v.rbegin()->first, *se.rbegin());
  for (int i = 0; i < n - 1; i++) {
    se.erase(se.find(v[i].second));
    r = min(r, v[i].first + *se.rbegin());
  }
  printf("%d\\n", r);
}

Error: -11

Fixed submission:

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

int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &n, &n);
  vector<pair<int, int>> v;
  multiset<int> se;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    v.emplace_back(a, b);
    se.insert(b);
  }
  sort(v.begin(), v.end());
  int r = min(v.rbegin()->first, *se.rbegin());
  for (int i = 0; i < n - 1; i++) {
    se.erase(v[i].second);
    r = min(r, v[i].first + *se.rbegin());
  }
  printf("%d\\n", r);
}
Problem p00360 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, sm = 1, num, n, las;
  string s, ans;
  cin >> s >> k;
  n = s.size();
  while (sm < n)
    sm *= 2;
  ll seg[sm * 2];
  set<pair<char, ll>> se;
  for (i = 0; i < sm * 2; ++i)
    seg[i] = 0;
  num = k + 1 < n ? k + 1 : n;
  las = num;
  for (i = 0; i < num; ++i)
    se.insert(make_pair(s[i], i));
  ll cnt = 0;
  while (k && ans.size() != n) {
    ++cnt;
    num = k + 1 < n - ans.size() ? k + 1 : n - ans.size();
    while (num > se.size() && las != n) {
      if (seg[sm + las] != -1)
        se.insert(make_pair(s[las], las));
      las++;
    }
    while (num < se.size()) {
      --las;
      if (seg[sm + las] != -1)
        se.erase(se.find(make_pair(s[las], las)));
    }
    ans = ans + (*se.begin()).first;
    ll nn = sm + (*se.begin()).second, nnum = (*se.begin()).second;
    while (nn)
      nnum -= seg[nn], nn /= 2;
    k -= nnum;
    ll now = sm + (*se.begin()).second;
    while (1) {
      while (!(now % 2))
        now /= 2;
      if (seg[now] != -1)
        seg[now]++;
      ll mm = 1;
      while (mm < now)
        mm *= 2;
      if (mm - now == 1 || now == 1)
        break;
      now++;
    }
    seg[(*se.begin()).second + sm] = -1;
    set<pair<char, ll>>::iterator it = se.begin();
    it++;
    se.erase(se.begin(), it);
  }
  for (i = 0; i < n; ++i)
    if (seg[sm + i] != -1)
      ans = ans + s[i];
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <set>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, sm = 1, num, n, las;
  string s, ans;
  cin >> s >> k;
  n = s.size();
  while (sm < k)
    sm *= 2;
  ll seg[sm * 2];
  set<pair<char, ll>> se;
  for (i = 0; i < sm * 2; ++i)
    seg[i] = 0;
  num = k + 1 < n ? k + 1 : n;
  las = num;
  for (i = 0; i < num; ++i)
    se.insert(make_pair(s[i], i));
  while (k && ans.size() != n) {
    num = k + 1 < n - ans.size() ? k + 1 : n - ans.size();
    while (num > se.size() && las != n) {
      if (seg[sm + las] != -1)
        se.insert(make_pair(s[las], las));
      las++;
    }
    while (num < se.size()) {
      --las;
      if (seg[sm + las] != -1)
        se.erase(se.find(make_pair(s[las], las)));
    }
    ans = ans + (*se.begin()).first;
    ll nn = sm + (*se.begin()).second, nnum = (*se.begin()).second;
    while (nn)
      nnum -= seg[nn], nn /= 2;
    k -= nnum;
    ll now = sm + (*se.begin()).second;
    while (1) {
      while (!(now % 2))
        now /= 2;
      if (seg[now] != -1)
        seg[now]++;
      ll mm = 1;
      while (mm < now)
        mm *= 2;
      if (mm - now == 1 || now == 1)
        break;
      now++;
    }
    seg[(*se.begin()).second + sm] = -1;
    set<pair<char, ll>>::iterator it = se.begin();
    it++;
    se.erase(se.begin(), it);
  }
  for (i = 0; i < n; ++i)
    if (seg[sm + i] != -1)
      ans = ans + s[i];
  cout << ans << endl;
  return 0;
}
Problem p00366 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int ret[1000000];

int main() {
  int n;
  cin >> n;
  int a[1000000], num = 0;
  lp(i, n) {
    cin >> a[i];
    num = max(a[i], num);
  }
  int ans = 0, memo, count;
  lp(i, n) {
    count = 0;
    memo = a[i];
    while (1) {
      if (num % a[i] == 0) {
        ret[memo] = count;
        break;
      }
      if (ret[memo] != 0) {
        ans += ret[memo];
        break;
      }
      a[i]++;
      ans++;
      count++;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[100000], num = 0;
  lp(i, n) {
    cin >> a[i];
    num = max(a[i], num);
  }
  int ans = 0;
  lp(i, n) {
    while (1) {
      if (num % a[i] == 0)
        break;
      a[i]++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00366 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int t[100000];
int main(void) {
  int n;
  int max;
  int i, j;
  int sum;
  int cnt, cnt2, MC[1000];
  cin >> n;
  max = -1;
  for (i = 0; i < n; i++) {
    cin >> t[i];
    if (max < t[i])
      max = t[i];
  }
  cnt = 1;
  cnt2 = 0;
  while (cnt != max) {
    if (max % cnt == 0) {
      MC[cnt2] = cnt;
      cnt2++;
    }
    cnt++;
  }
  MC[cnt2] = max;
  cnt2++;
  /*	cout<<MC[cnt2]<<endl;
          for(i=0;i<cnt2;i++) cout<<MC[i]<<" ";
          cout<<endl;*/

  sum = 0;
  for (i = 0; i < n; i++) {
    if (max % t[i] != 0) {
      for (j = 0; j < cnt2; j++) {
        if (MC[j] > t[i]) {
          sum += MC[j] - t[i];
          break;
        }
      }
    }
  }

  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, t[100000];
  int max;
  int i, j;
  int sum;
  int cnt, cnt2, MC[1000], C;
  cin >> n;
  max = -1;
  for (i = 0; i < n; i++) {
    cin >> t[i];
    if (max < t[i])
      max = t[i];
  }
  cnt = 2;
  cnt2 = 0;
  while (cnt != max) {
    if (max % cnt == 0) {
      MC[cnt2] = cnt;
      cnt2++;
    }
    cnt++;
  }
  MC[cnt2] = max;
  cnt2++;
  //	cout<<MC[cnt2]<<endl;
  //	for(i=0;i<cnt2;i++) cout<<MC[i]<<" ";
  //	cout<<endl;

  sum = 0;
  C = 0;
  for (i = 0; i < n; i++) {
    if (max % t[i] != 0) {
      for (j = 0; j < cnt2; j++) {
        if (MC[j] > t[i]) {
          sum += MC[j] - t[i];
          break;
        }
      }
    }
  }

  cout << sum << endl;

  return 0;
}
Problem p00366 (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;

int t[100000];
int main() {
  int n;
  scanf("%d", &n);
  int Max = 0;
  rep(i, n) {
    scanf("%d", &t[i]);
    Max = max(Max, t[i]);
  }
  vector<int> v;
  for (int i = 1; i * i <= Max; i++) {
    if (Max % i == 0) {
      v.push_back(i);
      v.push_back(Max / i);
    }
  }
  sort(v.begin(), v.end());
  int cnt = 0;
  rep(i, n) { cnt += *lower_bound(v.begin(), v.end(), t[i]) - t[i]; }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

int t[100000];
int main() {
  int n;
  scanf("%d", &n);
  int Max = 0;
  rep(i, n) {
    scanf("%d", &t[i]);
    Max = max(Max, t[i]);
  }
  int cnt = 0;
  rep(i, n) {
    while (Max % t[i]) {
      cnt++;
      t[i]++;
    }
  }
  cout << cnt << endl;
}
Problem p00366 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int a[114514];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  vector<int> v;
  for (int i = 1; i <= a[n - 1]; i++)
    if (a[n - 1] % i == 0)
      v.push_back(i);
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (v[j] >= a[i]) {
        ans += v[j] - a[i];
        goto heaven;
      }
    }
  heaven:;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[114514];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    while (a[n - 1] % a[i] != 0) {
      ans++;
      a[i]++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00366 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long int ans = 0;
  int N, temp[100010], ma = 0, i, j, temp3;
  cin >> N;

  ma = temp[0];
  for (i = 0; i < N; i++) {
    cin >> temp[i];
    ma = max(ma, temp[i]);
  }
  for (i = 0; i < N; i++) {
    temp3 = ma;
    for (j = 1; j * j <= ma; j++) {
      if (ma % j == 0) {
        if (j >= temp[i])
          temp3 = min(j - temp[i], temp3);
        if (ma / j >= temp[i])
          temp3 = min(ma / j - temp[i], temp3);
      }
    }
    ans += temp3;
  }

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


Error: 0

Fixed submission:

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

int main() {
  long long int ans = 0;
  int N, temp[10100], ma = 0, i, j, temp3;
  cin >> N;

  ma = temp[0];
  for (i = 0; i < N; i++) {
    cin >> temp[i];
    ma = max(ma, temp[i]);
  }
  for (i = 0; i < N; i++) {
    for (j = temp[i]; j <= ma; j++) {
      if (ma % j == 0) {
        break;
      }
    }
    ans += j - temp[i];
  }

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

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

int n;
int ax[50], bx[50];
int ay[50], by[50];
int az[50], bz[50];

int input() {
  int fi, se;
  cin >> fi >> se;
  return fi * 60 + se;
}

int main() {
  cin >> n;
  vector<int> X, Y, Z;
  for (int i = 0; i < n; i++) {
    ax[i] = input();
    bx[i] = input();
    ay[i] = input();
    by[i] = input();
    az[i] = input();
    bz[i] = input();
    X.push_back(ax[i]);
    Y.push_back(ay[i]);
    Z.push_back(az[i]);
  }

  typedef pair<int, int> P;
  P t[100];

  int maxm = 0;
  for (int I = 0; I < (int)X.size(); I++) {
    int p = X[I];
    for (int J = 0; J < (int)Y.size(); J++) {
      int q = Y[J];
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (ax[i] <= p && p <= bx[i]) {
          if (ay[i] <= q && q <= by[i]) {
            t[cnt++] = P(az[i], 1);
            t[cnt++] = P(bz[i] + 1, -1);
          }
        }
      }
      sort(t, t + cnt);
      int v = 0, sum = 0;
      for (int i = 0; i < cnt; i++) {
        sum += t[i].second;
        v = max(v, sum);
      }
      maxm = max(maxm, v);
    }
  }
  cout << maxm << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int n;
int ax[50], bx[50];
int ay[50], by[50];
int az[50], bz[50];

int input() {
  int fi, se;
  cin >> fi >> se;
  return fi * 60 + se;
}

int main() {
  cin >> n;
  vector<int> X, Y, Z;
  for (int i = 0; i < n; i++) {
    ax[i] = input();
    bx[i] = input();
    ay[i] = input();
    by[i] = input();
    az[i] = input();
    bz[i] = input();
    X.push_back(ax[i]);
    Y.push_back(ay[i]);
    Z.push_back(az[i]);
  }

  typedef pair<int, int> P;
  P t[50];

  int maxm = 0;
  for (int I = 0; I < (int)X.size(); I++) {
    int p = X[I];
    for (int J = 0; J < (int)Y.size(); J++) {
      int q = Y[J];
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (ax[i] <= p && p <= bx[i]) {
          if (ay[i] <= q && q <= by[i]) {
            t[cnt++] = P(az[i], 1);
            t[cnt++] = P(bz[i] + 1, -1);
          }
        }
      }
      sort(t, t + cnt);
      int v = 0, sum = 0;
      for (int i = 0; i < cnt; i++) {
        sum += t[i].second;
        v = max(v, sum);
      }
      maxm = max(maxm, v);
    }
  }
  cout << maxm << endl;
  return 0;
}
Problem p00369 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int N;
int A[111111];

signed main() {
  string s;
  cin >> s;
  N = s.size();
  rep(i, N) A[i] = s[i] - '0';

  int ans = 9;

  chmin(ans, *max_element(A, A + N) - *min_element(A, A + N));

  int ma = 0, mi = INT_MAX;
  for (int i = 0; i < N; i++) {
    if (A[i] == 1 && i + 1 < N) {
      chmax(ma, A[i + 1] + 10);
      i++;
    } else {
      chmin(mi, A[i]);
    }
  }

  if (ma != 0 && mi != INT_MAX)
    chmin(ans, ma - mi);

  for (int i = 2; i < N; i++) {
    if (N % i)
      continue;
    string mi(1, '9' + 1);
    string ma(1, '0' - 1);

    for (int j = 0; j < N; j += i) {
      string s;
      for (int k = 0; k < i; k++)
        s += (char)(A[j + k] + '0');
      if (mi > s)
        mi = s;
      if (ma < s)
        ma = s;
    }

    if (mi.substr(0, i - 2) != ma.substr(0, i - 2))
      continue;
    int x = (mi[i - 2] - '0') * 10 + mi[i - 1] - '0';
    int y = (ma[i - 2] - '0') * 10 + ma[i - 1] - '0';
    chmin(ans, y - x);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int N;
int A[111111];

signed main() {
  string s;
  cin >> s;
  N = s.size();
  rep(i, N) A[i] = s[i] - '0';

  int ans = 9;

  chmin(ans, *max_element(A, A + N) - *min_element(A, A + N));

  int ma = 0, mi = INT_MAX;
  for (int i = 0; i < N; i++) {
    if (A[i] == 1 && i + 1 < N) {
      chmax(ma, A[i + 1] + 10);
      i++;
    } else {
      chmin(mi, A[i]);
    }
  }

  if (ma != 0 && mi != INT_MAX)
    chmin(ans, ma - mi);

  for (int i = 2; i < N; i++) {
    string mi(1, '9' + 1);
    string ma(1, '0' - 1);

    for (int j = 0; j < N; j += i) {
      string s;
      for (int k = 0; k < i; k++)
        s += (char)(A[j + k] + '0');
      if (mi > s)
        mi = s;
      if (ma < s)
        ma = s;
    }

    if (mi.substr(0, i - 2) != ma.substr(0, i - 2))
      continue;
    int x = (mi[i - 2] - '0') * 10 + mi[i - 1] - '0';
    int y = (ma[i - 2] - '0') * 10 + ma[i - 1] - '0';
    chmin(ans, y - x);
  }
  cout << ans << endl;
  return 0;
}