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

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

int d, n;
int t[202];
int a[202], b[202], c[202];

int memo[256][256];

int dfs(int i, int pre) {
  if (i == d - 1) {
    int maxi = 0;
    for (int x = 0; x < n; x++) {
      if (a[x] <= t[i] && t[i] <= b[x]) {
        maxi = max(maxi, abs(c[pre] - c[x]));
      }
    }
    return maxi;
  }
  int &maxi = memo[i][pre];
  if (maxi != -1)
    return maxi;
  maxi = 0;
  for (int x = 0; x < n; x++) {
    if (a[x] <= t[i] && t[i] <= b[x]) {
      maxi = max(maxi, dfs(i + 1, x) + abs(c[pre] - c[x]));
    }
  }
  return maxi;
}

int main() {
  memset(memo, -1, sizeof(memo));
  cin >> d >> n;
  for (int i = 0; i < d; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  int maxi = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= t[0] && t[0] <= b[i]) {
      maxi = max(maxi, dfs(1, i));
    }
  }

  cout << maxi << endl;
}

Error: TLE

Fixed submission:

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

int d, n;
int t[202];
int po[70][2];

int dfs(int i = 0, int cost = 0, int front = 0) {
  if (i == d)
    return cost;
  if (i == 0) {
    return max(dfs(i + 1, 0, po[t[i]][0]), dfs(i + 1, 0, po[t[i]][1]));
  }

  return max(dfs(i + 1, cost + abs(front - po[t[i]][0]), po[t[i]][0]),
             dfs(i + 1, cost + abs(front - po[t[i]][1]), po[t[i]][1]));
}

int main() {
  cin >> d >> n;
  for (int i = 0; i < d; i++) {
    cin >> t[i];
  }

  for (int i = 0; i < 70; i++) {
    po[i][0] = 1e9;
    po[i][1] = -1;
  }

  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    for (int l = a; l <= b; l++) {
      po[l][0] = min(po[l][0], c);
      po[l][1] = max(po[l][1], c);
    }
  }

  cout << dfs() << endl;
}
Problem p00502 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define llong long long
typedef struct data {
  int low;
  int high;
  int eva;
} data;
int D, N;
int temp[201];
data kind[200];
int score[201][200][200];

int solve(int d, int k, int yk) {
  if (score[d][k][yk] != -1)
    return score[d][k][yk];
  if (d == D)
    return score[d][k][yk] = fabs(kind[k].eva - kind[yk].eva);

  int e = 0;
  for (int i = 0; i < N; i++) {
    data use = kind[i];
    if (use.low > temp[d + 1] || use.high < temp[d + 1])
      continue;
    int sum;
    if (d > 1)
      sum = fabs(kind[k].eva - kind[yk].eva) + solve(d + 1, i, k);
    else
      sum = solve(d + 1, i, k);
    e = max(e, sum);
  }

  return score[d][k][yk] = e;
}

int main() {
  fill_n(temp, 201, -1);
  fill_n(**score, 201 * 200 * 200, -1);
  cin >> D >> N;
  for (int i = 1; i <= D; i++) {
    cin >> temp[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> kind[i].low >> kind[i].high >> kind[i].eva;
  }

  cout << solve(0, 0, 0) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define llong long long
typedef struct data {
  int low;
  int high;
  int eva;
} data;
int D, N;
int temp[201];
data kind[200];
int score[201][200];

int solve(int d, int k, int e) {
  // cout << d << " " << k << " " << e << "   " << score[d][k] << endl;
  if (score[d][k] >= e)
    return 0;
  score[d][k] = e;
  if (d == D)
    return score[d][k] = e;

  int ret = 0;
  for (int i = 0; i < N; i++) {
    data use = kind[i];
    if (use.low > temp[d + 1] || use.high < temp[d + 1])
      continue;
    int nexte = e + fabs(use.eva - kind[k].eva);
    if (d > 0)
      ret = max(ret, solve(d + 1, i, nexte));
    else
      ret = max(ret, solve(d + 1, i, e));
  }

  return ret;
}

int main() {
  fill_n(temp, 201, -1);
  fill_n(*score, 201 * 200, -1);
  cin >> D >> N;
  for (int i = 1; i <= D; i++) {
    cin >> temp[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> kind[i].low >> kind[i].high >> kind[i].eva;
  }

  cout << solve(0, 0, 0) << endl;
  return 0;
}
Problem p00502 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int wear[200][3], day[200];
int mem[200][200];
int D, N;
int dp(int d, int b) {
  if (d == D)
    return 0;
  if (mem[d][b] != -1)
    return mem[d][b];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (wear[i][0] <= day[d] && wear[i][1] >= day[d])
      ans = max(ans, dp(d + 1, i) + abs(wear[i][2] - wear[b][2]));
  }
  mem[d][b] = ans;
  return ans;
}

int main() {
  for (int i = 0; i < 200; i++)
    for (int j = 0; j < 200; j++)
      mem[i][j] = -1;

  cin >> D >> N;
  for (int i = 0; i < D; i++)
    cin >> day[i];
  for (int i = 0; i < N; i++)
    cin >> wear[i][0] >> wear[i][1] >> wear[i][2];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (wear[i][0] <= day[0] && wear[i][1] >= day[0])
      ans = max(ans, dp(1, i));
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int wear[200][3], day[200];
int mem[200][200];
int D, N;
int dp(int d, int b) {
  if (d == D)
    return 0;
  if (mem[d][b] != -1)
    return mem[d][b];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (wear[i][0] <= day[d] && wear[i][1] >= day[d])
      ans = max(ans, dp(d + 1, i) + abs(wear[i][2] - wear[b][2]));
  }
  return ans;
}

int main() {
  for (int i = 0; i < 200; i++)
    for (int j = 0; j < 200; j++)
      mem[i][j] = -1;

  cin >> D >> N;
  for (int i = 0; i < D; i++)
    cin >> day[i];
  for (int i = 0; i < N; i++)
    cin >> wear[i][0] >> wear[i][1] >> wear[i][2];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (wear[i][0] <= day[0] && wear[i][1] >= day[0])
      ans = max(ans, dp(1, i));
  }
  cout << ans << endl;
}
Problem p00502 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {

  int d, n, t, a, b, c, dp[202][202];
  vector<int> T, A, B, C;

  cin >> d >> n;
  T.clear();
  A.clear();
  B.clear();
  C.clear();

  for (int i = 0; i < d; i++) {
    cin >> t;
    T.push_back(t);
  }

  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
  }

  for (int i = 0; i < 202; i++)
    for (int j = 0; j < 202; j++)
      dp[i][j] = -1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {

      if (A[i] <= T[0] && T[0] <= B[i] && A[j] <= T[1] && T[1] <= B[j])
        dp[0][j] = max(dp[0][j], abs(C[i] - C[j]));
    }
  }

  for (int i = 1; i <= d; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (A[k] <= T[i + 1] && T[i + 1] <= B[k] && dp[i - 1][j] >= 0)
          dp[i][k] = max(dp[i][k], dp[i - 1][j] + abs(C[j] - C[k]));
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[d - 2][i]);
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {

  int d, n, t, a, b, c, dp[202][202];
  vector<int> T, A, B, C;

  while (cin >> d >> n, d | n) {
    T.clear();
    A.clear();
    B.clear();
    C.clear();

    for (int i = 0; i < d; i++) {
      cin >> t;
      T.push_back(t);
    }

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      A.push_back(a);
      B.push_back(b);
      C.push_back(c);
    }

    for (int i = 0; i < 202; i++)
      for (int j = 0; j < 202; j++)
        dp[i][j] = -1;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {

        if (A[i] <= T[0] && T[0] <= B[i] && A[j] <= T[1] && T[1] <= B[j])
          dp[0][j] = max(dp[0][j], abs(C[i] - C[j]));
      }
    }

    for (int i = 1; i <= d; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (A[k] <= T[i] && T[i] <= B[k] && dp[i - 1][j] >= 0)
            dp[i][k] = max(dp[i][k], dp[i - 1][j] + abs(C[j] - C[k]));
        }
      }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, dp[d - 1][i]);
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
struct P {
  int min, max, hade;
};
P b[300];
int d, n, t[300];
vector<int> a[300];
int dp[300][300];
int solve(int i, int mae) {
  if (i == d)
    return 0;
  int sum = 0;
  for (int j = 0; j < a[i].size(); j++) {
    int res = mae - b[a[i][j]].hade;
    res = max(res, 0 - res);
    if (dp[i + 1][a[i][j]] != -1) {
      sum = max(sum, res + dp[i + 1][a[i][j]]);
    } else {
      dp[i + 1][a[i][j]] = solve(i + 1, b[a[i][j]].hade);
      sum = max(sum, dp[i + 1][a[i][j]] + res);
    }
  }
  return sum;
}
int main() {
  cin >> d >> n;
  for (int i = 0; i < d; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].min >> b[i].max >> b[i].hade;
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      if (b[j].min <= t[i] && b[j].max >= t[i]) {
        a[i].push_back(j);
      }
    }
  }
  for (int i = 0; i <= d; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = -1;
    }
  }
  int sum = 0;
  for (int i = 0; i < a[0].size(); i++) {
    if (dp[0][a[0][i]] != -1) {
      sum = max(sum, a[0][i] - dp[1][a[0][i]]);
    } else {
      sum = max(sum, dp[1][a[0][i]] = solve(1, b[a[0][i]].hade));
    }
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
struct P {
  int min, max, hade;
};
P b[200];
int d, n, t[200];
vector<int> a[200];
int dp[200][200];
int solve(int i, int mae) {
  if (i == d)
    return 0;
  int sum = 0;
  for (int j = 0; j < a[i].size(); j++) {
    int res = mae - b[a[i][j]].hade;
    res = max(res, 0 - res);
    if (dp[i + 1][a[i][j]] != -1) {
      sum = max(sum, res + dp[i + 1][a[i][j]]);
    } else {
      dp[i + 1][a[i][j]] = solve(i + 1, b[a[i][j]].hade);
      sum = max(sum, dp[i + 1][a[i][j]] + res);
    }
  }
  return sum;
}
int main() {
  cin >> d >> n;
  for (int i = 0; i < d; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].min >> b[i].max >> b[i].hade;
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      if (b[j].min <= t[i] && b[j].max >= t[i]) {
        a[i].push_back(j);
      }
    }
  }
  for (int i = 0; i <= d; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = -1;
    }
  }
  int sum = 0;
  for (int i = 0; i < a[0].size(); i++) {
    if (dp[0][a[0][i]] != -1) {
      sum = max(sum, a[0][i] - dp[1][a[0][i]]);
    } else {
      sum = max(sum, dp[1][a[0][i]] = solve(1, b[a[0][i]].hade));
    }
  }
  cout << sum << endl;
}
Problem p00503 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

map<ll, int> zipX, zipY, zipD;
ll unzipX[128], unzipY[128], unzipD[128];
int W, H, Z, N, K;
vector<int> X, Y, D;
int sea[128][128][128];

int compress(vector<int> crd, map<ll, int> &zip, ll unzip[128]) {
  sort(crd.begin(), crd.end());
  crd.erase(unique(crd.begin(), crd.end()), crd.end());
  for (int i = 0; i < crd.size(); i++) {
    zip[crd[i]] = i;
    unzip[i] = crd[i];
  }
  return crd.size();
}

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    int x, y, d;
    scanf("%d%d%d", &x, &y, &d);
    X.push_back(x);
    Y.push_back(y);
    D.push_back(d);
    scanf("%d%d%d", &x, &y, &d);
    X.push_back(x);
    Y.push_back(y);
    D.push_back(d);
  }

  H = compress(Y, zipY, unzipY);
  W = compress(X, zipX, unzipX);
  Z = compress(D, zipD, unzipD);

  for (int i = 0; i < 2 * N; i += 2) {
    for (int y = zipY[Y[i]]; y < zipY[Y[i + 1]]; y++)
      for (int x = zipX[X[i]]; x < zipX[X[i + 1]]; x++)
        for (int d = zipD[D[i]]; d < zipD[D[i + 1]]; d++)
          sea[y][x][d]++;
  }
  ll res = 0;
  for (int y = 0; y < 128; y++)
    for (int x = 0; x < 128; x++)
      for (int d = 0; d < 128; d++)
        if (sea[y][x][d] >= K)
          res += abs(unzipY[y] - unzipY[y + 1]) *
                 abs(unzipX[x] - unzipX[x + 1]) *
                 abs(unzipD[d] - unzipD[d + 1]);

  printf("%lld\\n", res);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

map<ll, int> zipX, zipY, zipD;
ll unzipX[64], unzipY[64], unzipD[64];
int W, H, Z, N, K;
vector<int> X, Y, D;
int sea[64][64][64];

int compress(vector<int> crd, map<ll, int> &zip, ll unzip[64]) {
  sort(crd.begin(), crd.end());
  crd.erase(unique(crd.begin(), crd.end()), crd.end());
  for (int i = 0; i < crd.size(); i++) {
    zip[crd[i]] = i;
    unzip[i] = crd[i];
  }
  return crd.size();
}

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    int x, y, d;
    scanf("%d%d%d", &x, &y, &d);
    X.push_back(x);
    Y.push_back(y);
    D.push_back(d);
    scanf("%d%d%d", &x, &y, &d);
    X.push_back(x);
    Y.push_back(y);
    D.push_back(d);
  }

  H = compress(Y, zipY, unzipY);
  W = compress(X, zipX, unzipX);
  Z = compress(D, zipD, unzipD);

  for (int i = 0; i < 2 * N; i += 2) {
    for (int y = zipY[Y[i]]; y < zipY[Y[i + 1]]; y++)
      for (int x = zipX[X[i]]; x < zipX[X[i + 1]]; x++)
        for (int d = zipD[D[i]]; d < zipD[D[i + 1]]; d++)
          sea[y][x][d]++;
  }
  ll res = 0;
  for (int y = 0; y < 64; y++)
    for (int x = 0; x < 64; x++)
      for (int d = 0; d < 64; d++)
        if (sea[y][x][d] >= K)
          res += abs(unzipY[y] - unzipY[y + 1]) *
                 abs(unzipX[x] - unzipX[x + 1]) *
                 abs(unzipD[d] - unzipD[d + 1]);

  printf("%lld\\n", res);
  return 0;
}
Problem p00503 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long lli;
const int MAX = 100;
int a[MAX][MAX][MAX];

int main() {
  int n, m;
  while (cin >> n >> m) {
    lli v[50][6], ans = 0;
    vector<lli> v2[3];
    set<lli> s[3];
    map<lli, int> v3[3];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 6; j++) {
        cin >> v[i][j];
        s[j % 3].insert(v[i][j]);
      }
    }

    for (int i = 0; i < MAX; i++)
      for (int j = 0; j < MAX; j++)
        for (int k = 0; k < MAX; k++)
          a[i][j][k] = 0;
    for (int i = 0; i < 3; i++) {
      for (set<lli>::iterator it = s[i].begin(); it != s[i].end(); it++) {
        v2[i].push_back(*it);
        v3[i][*it] = v2[i].size() - 1;
      }
    }

    for (int i = 0; i < n; i++)
      for (int j = v3[0][v[i][0]]; j < v3[0][v[i][3]]; j++)
        for (int k = v3[1][v[i][1]]; k < v3[1][v[i][4]]; k++)
          for (int l = v3[2][v[i][2]]; l < v3[2][v[i][5]]; l++)
            a[j][k][l]++;

    for (int i = 0; i < MAX - 1; i++)
      for (int j = 0; j < MAX - 1; j++)
        for (int k = 0; k < MAX - 1; k++)
          if (a[i][j][k] >= m)
            ans += (v2[0][i + 1] - v2[0][i]) * (v2[1][j + 1] - v2[1][j]) *
                   (v2[2][k + 1] - v2[2][k]);

    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

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

typedef long long lli;
const int MAX = 300;
int a[MAX][MAX][MAX];

int main() {
  int n, m;
  while (cin >> n >> m) {
    lli v[50][6], ans = 0;
    vector<lli> v2[3];
    set<lli> s[3];
    map<lli, int> v3[3];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 6; j++) {
        cin >> v[i][j];
        s[j % 3].insert(v[i][j]);
      }
    }

    for (int i = 0; i < MAX; i++)
      for (int j = 0; j < MAX; j++)
        for (int k = 0; k < MAX; k++)
          a[i][j][k] = 0;
    for (int i = 0; i < 3; i++) {
      for (set<lli>::iterator it = s[i].begin(); it != s[i].end(); it++) {
        v2[i].push_back(*it);
        v3[i][*it] = v2[i].size() - 1;
      }
    }

    for (int i = 0; i < n; i++)
      for (int j = v3[0][v[i][0]]; j < v3[0][v[i][3]]; j++)
        for (int k = v3[1][v[i][1]]; k < v3[1][v[i][4]]; k++)
          for (int l = v3[2][v[i][2]]; l < v3[2][v[i][5]]; l++)
            a[j][k][l]++;

    for (int i = 0; i < MAX - 1; i++)
      for (int j = 0; j < MAX - 1; j++)
        for (int k = 0; k < MAX - 1; k++)
          if (a[i][j][k] >= m)
            ans += (v2[0][i + 1] - v2[0][i]) * (v2[1][j + 1] - v2[1][j]) *
                   (v2[2][k + 1] - v2[2][k]);

    cout << ans << endl;
  }
}
Problem p00503 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long lli;
const int MAX = 100;
int a[MAX][MAX][MAX];

int main() {
  int n, m;
  while (cin >> n >> m) {
    lli v[50][6], ans = 0;
    vector<lli> v2[3];
    set<lli> s[3];
    map<lli, int> v3[3];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 6; j++) {
        cin >> v[i][j];
        s[j % 3].insert(v[i][j]);
      }
    }

    for (int i = 0; i < MAX; i++)
      for (int j = 0; j < MAX; j++)
        for (int k = 0; k < MAX; k++)
          a[i][j][k] = 0;
    for (int i = 0; i < 3; i++) {
      for (set<lli>::iterator it = s[i].begin(); it != s[i].end(); it++) {
        v2[i].push_back(*it);
        v3[i][*it] = v2[i].size() - 1;
      }
    }

    for (int i = 0; i < n; i++)
      for (int j = v3[0][v[i][0]]; j < v3[0][v[i][3]]; j++)
        for (int k = v3[1][v[i][1]]; k < v3[1][v[i][4]]; k++)
          for (int l = v3[2][v[i][2]]; l < v3[2][v[i][5]]; l++)
            a[j][k][l]++;

    for (int i = 0; i < MAX - 1; i++)
      for (int j = 0; j < MAX - 1; j++)
        for (int k = 0; k < MAX - 1; k++)
          if (a[i][j][k] >= m)
            ans += (v2[0][i + 1] - v2[0][i]) * (v2[1][j + 1] - v2[1][j]) *
                   (v2[2][k + 1] - v2[2][k]);

    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

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

typedef long long lli;
const int MAX = 300;
int a[MAX][MAX][MAX];

int main() {
  int n, m;
  while (cin >> n >> m) {
    lli v[50][6], ans = 0;
    vector<lli> v2;
    set<lli> s;
    map<lli, int> v3;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 6; j++) {
        cin >> v[i][j];
        s.insert(v[i][j]);
      }
    }

    for (int i = 0; i < MAX; i++)
      for (int j = 0; j < MAX; j++)
        for (int k = 0; k < MAX; k++)
          a[i][j][k] = 0;
    for (set<lli>::iterator it = s.begin(); it != s.end(); it++) {
      v2.push_back(*it);
      v3[*it] = v2.size() - 1;
    }

    for (int i = 0; i < n; i++)
      for (int j = v3[v[i][0]]; j < v3[v[i][3]]; j++)
        for (int k = v3[v[i][1]]; k < v3[v[i][4]]; k++)
          for (int l = v3[v[i][2]]; l < v3[v[i][5]]; l++)
            a[j][k][l]++;

    for (int i = 0; i < MAX - 1; i++)
      for (int j = 0; j < MAX - 1; j++)
        for (int k = 0; k < MAX - 1; k++)
          if (a[i][j][k] >= m)
            ans +=
                (v2[i + 1] - v2[i]) * (v2[j + 1] - v2[j]) * (v2[k + 1] - v2[k]);

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

#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, q;
long long x[110], y[110], z[110], ans;
long long a[110][2], b[110][2], c[110][2];
int main() {
  cin >> n >> q;
  rep(i, 2 * n) {
    cin >> x[i] >> y[i] >> z[i];
    a[i / 2][i % 2] = x[i];
    b[i / 2][i % 2] = y[i];
    c[i / 2][i % 2] = z[i];
  }
  sort(x, x + n * 2);
  sort(y, y + n * 2);
  sort(z, z + n * 2);
  ans = 0;
  rep(i, n * 2 - 1) rep(j, n * 2 - 1) rep(k, n * 2 - 1) {
    int cnt = 0;
    rep(t, n) {
      bool ok = true;
      rep(r, 2) {
        if (a[t][0] > x[i + r] || x[i + r] > a[t][1])
          ok = false;
        if (b[t][0] > y[j + r] || y[j + r] > b[t][1])
          ok = false;
        if (c[t][0] > z[k + r] || z[k + r] > c[t][1])
          ok = false;
      }
      if (ok)
        cnt++;
    }
    if (cnt >= q)
      ans += (x[i + 1] - x[i]) * (y[j + 1] - y[j]) * (z[k + 1] - z[k]);
  }
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int q[20000][7], p[6], qtop;
bool ICV(int c[], int d[]) {
  bool ret = true;
  for (int i = 0; i < 3; i++) {
    if (d[i] < c[i + 3] && d[i + 3] > c[i])
      p[i] = max(c[i], d[i]), p[i + 3] = min(c[i + 3], d[i + 3]);
    else
      ret = false;
  }
  return ret;
}
int main() {
  int n, e;
  cin >> n >> e;
  qtop = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++)
      cin >> q[qtop][j];
    q[qtop][6] = 1;
    int keep = qtop;
    qtop++;
    for (int j = 0; j < keep; j++) {
      if (ICV(q[keep], q[j])) {
        for (int k = 0; k < 6; k++)
          q[qtop][k] = p[k];
        q[qtop][6] = q[j][6] + 1;
        qtop++;
      }
    }
  }
  long long ans[60] = {0};
  for (int i = 55; i > 0; i--) {
    for (int j = 0; j < qtop; j++) {
      if (q[j][6] == i) {
        long long v[3] = {q[j][3] - q[j][0], q[j][4] - q[j][1],
                          q[j][5] - q[j][2]};
        ans[i] += v[0] * v[1] * v[2];
      }
    }
    ans[i - 1] -= ans[i];
  }
  cout << ans[e] << endl;
  return 0;
}