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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
struct R {
  int x1, x2, add;
  R(int _x1, int _x2, int _add) { x1 = _x1, x2 = _x2, add = _add; }
};
vector<R> V[10001];
int field[2][10000];
int X1, X2, Y1, Y2;
int main() {
  int n, r;
  while (scanf("%d %d", &n, &r), n) {
    memset(field, 0, sizeof(field));
    for (int i = 0; i <= 10000; i++)
      V[i].clear();
    X1 = 10000, Y1 = 10000, X2 = 0, Y2 = 0;
    for (int i = 0; i < n; i++) {
      int x1, y1, x2, y2;
      scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
      V[y1].push_back(R(x1, x2, 1));
      V[y2].push_back(R(x1, x2, -1));
      X1 = min(x1, X1);
      Y1 = min(y1, Y1);
      X2 = max(x2, X2);
      Y2 = max(y2, Y2);
    }
    int Y = 1;
    int S = 0, L = 0;
    for (int y = Y1; y <= Y2; y++, Y = !Y) {
      for (int x = X1; x < X2; x++)
        field[Y][x] = field[!Y][x];
      for (int i = 0; i < V[y].size(); i++)
        for (int x = V[y][i].x1; x < V[y][i].x2; x++)
          field[Y][x] += V[y][i].add;
      for (int x = X1; x < X2; x++) {
        if (0 < field[Y][x]) {
          S++;
          if (x == 0 || field[Y][x - 1] == 0)
            L++;
          if (x == 9999 || field[Y][x + 1] == 0)
            L++;
        }
        if ((field[Y][x] == 0 && 0 < field[!Y][x]) ||
            (0 < field[Y][x] && field[!Y][x] == 0))
          L++;
      }
    }
    printf("%d\\n", S);
    if (r == 2)
      printf("%d\\n", L);
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int field[10001][10001];
int X1, X2, Y1, Y2;
int main() {
  int n, r;
  while (scanf("%d %d", &n, &r), n) {
    memset(field, 0, sizeof(field));
    X1 = 10000, Y1 = 10000, X2 = 0, Y2 = 0;
    for (int i = 0; i < n; i++) {
      int x1, y1, x2, y2;
      scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
      field[x1][y1]++;
      field[x2][y1]--;
      field[x1][y2]--;
      field[x2][y2]++;
      X1 = min(x1, X1);
      Y1 = min(y1, Y1);
      X2 = max(x2, X2);
      Y2 = max(y2, Y2);
    }
    for (int i = Y1; i <= Y2; i++) {
      for (int j = X1 + 1; j <= X2; j++) {
        field[j][i] += field[j - 1][i];
      }
    }
    for (int i = X1; i <= X2; i++) {
      for (int j = Y1 + 1; j <= Y2; j++) {
        field[i][j] += field[i][j - 1];
      }
    }
    int S = 0;
    for (int i = X1; i < X2; i++)
      for (int j = Y1; j < Y2; j++)
        if (field[i][j] > 0)
          S++;
    printf("%d\\n", S);
    if (r == 2) {
      int LEN = 0;
      for (int i = X1; i < X2; i++)
        for (int j = Y1; j < Y2; j++) {
          if (field[i][j]) {
            LEN += (!i || !field[i - 1][j]) + (!j || !field[i][j - 1]);
            LEN += !field[i + 1][j] + !field[i][j + 1];
          }
        }
      printf("%d\\n", LEN);
    }
  }
}
Problem p00432 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int sum[2][10001], c[2][10001];
vector<int> E[10001], G[10001];
int main() {
  int n, r;
  while (scanf("%d%d", &n, &r), n) {
    memset(sum, 0, sizeof(sum));
    memset(c, 0, sizeof(c));
    rep(i, 10001) E[i].clear(), G[i].clear();
    int h = 0, w = 0;
    rep(i, n) {
      int x1, y1, x2, y2;
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      h = max(h, x2 + 1);
      w = max(w, y2 + 1);
      E[x1].push_back(y1);
      E[x2].push_back(y2);
      G[x1].push_back(y2);
      G[x2].push_back(y1);
    }
    int a = 0, b = 0;
    rep(i, h) {
      rep(j, w) sum[i & 1][j] = c[i & 1][j] = c[!(i & 1)][j];
      for (int j : E[i])
        sum[i & 1][j]++, c[i & 1][j]++;
      for (int j : G[i])
        sum[i & 1][j]--, c[i & 1][j]--;
      for (int j = 1; j < w; j++)
        sum[i & 1][j] += sum[i & 1][j - 1];
      rep(j, w) {
        if (sum[i & 1][j])
          a++;
        if (!sum[i & 1][j] != !sum[!(i & 1)][j])
          b++;
        if (j == 0 && sum[i & 1][j])
          b++;
        if (j && !sum[i & 1][j] != !sum[i & 1][j - 1])
          b++;
      }
    }
    printf("%d\\n", a);
    if (r == 2)
      printf("%d\\n", b);
  }
}

Error: MLE

Fixed submission:

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

int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
int main() {
  int n, r;
  while (scanf("%d%d", &n, &r), n) {
    map<short, map<short, short>> sum;
    int h = 0, w = 0;
    rep(i, n) {
      int x1, y1, x2, y2;
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      h = max(h, x2);
      w = max(w, y2);
      sum[x1][y1]++;
      sum[x1][y2]--;
      sum[x2][y1]--;
      sum[x2][y2]++;
    }
    h++;
    w++;
    rep(i, h) for (int j = 1; j < w; j++) sum[i][j] += sum[i][j - 1];
    rep(i, w) for (int j = 1; j < h; j++) sum[j][i] += sum[j - 1][i];
    int a = 0, b = 0;
    rep(i, h) rep(j, w) {
      if (sum[i][j]) {
        a++;
        rep(k, 4) {
          int nx = i + dx[k], ny = j + dy[k];
          if (nx < 0 || nx >= h || ny < 0 || ny >= w || !sum[nx][ny])
            b++;
        }
      }
    }
    printf("%d\\n", a);
    if (r == 2)
      printf("%d\\n", b);
  }
}
Problem p00432 (C++) — buggy submission, verdict: Time Limit Exceeded

#import <algorithm>
#import <iostream>
#import <vector>
using namespace std;
typedef pair<int, int> P;
typedef vector<P> L;
typedef L::iterator I;
int U(L &l, I i, I j) {
  int r = i->second >= j->first;
  if (r) {
    i->second = max(i->second, j->second);
    l.erase(j);
  }
  return r;
}
void A(L &l, P p) {
  I i = lower_bound(l.begin(), l.end(), p);
  i = l.insert(i, p);
  I j;
  for (; j = i, ++j != l.end() && U(l, i, j);)
    ;
  for (; i != l.begin() && (j = i, U(l, --i, j));)
    ;
}
main() {
  int n, r;
  for (; cin >> n >> r, r;) {
    L v[10000], h[10000];
    for (; n--;) {
      int x1, y1, x2, y2, x, y;
      cin >> x1 >> y1 >> x2 >> y2;
      for (x = x1; x < x2; x++) {
        A(v[x], P(y1, y2));
      }
      for (y = y1; y < y2; y++) {
        A(h[y], P(x1, x2));
      }
    }
    int s = 0, c = 0;
    for (int y = 0; y < 10000; y++) {
      for (I i = h[y].begin(); i != h[y].end(); ++i)
        s += i->second - i->first;
      c += h[y].size() + v[y].size();
    }
    cout << s << endl;
    if (r == 2) {
      cout << c * 2 << endl;
    }
  }
  {
    int n;
    for (n = 2e6; n--;)
      getchar();
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
using namespace std;
typedef pair<int, int> P;
typedef list<P> L;
typedef L::iterator I;
int unite(L &l, I i, I j) {
  int r = i->second >= j->first;
  if (r) {
    i->second = max(i->second, j->second);
    l.erase(j);
  }
  return r;
}
void add(L &l, P p) {
  I i = lower_bound(l.begin(), l.end(), p);
  i = l.insert(i, p);
  I j;
  for (; j = i, ++j != l.end() && unite(l, i, j);)
    ;
  for (; i != l.begin() && (j = i, unite(l, --i, j));)
    ;
}
int main() {
  int n, r;
  for (; cin >> n >> r, r;) {
    L v[10000], h[10000];
    for (; n--;) {
      int x1, y1, x2, y2, x, y;
      cin >> x1 >> y1 >> x2 >> y2;
      /*for(x=x1;x<x2;x++){
              add(v[x],P(y1,y2));
      }*/
      for (y = y1; y < y2; y++) {
        add(h[y], P(x1, x2));
      }
    }
    int s = 0, c = 0;
    for (int y = 0; y < 10000; y++) {
      for (I i = h[y].begin(); i != h[y].end(); ++i)
        s += i->second - i->first;
      // c+=h[y].size()+v[y].size();
    }
    cout << s << endl;
    if (r == 2) {
      cout << c * 2 << endl;
    }
  }
  cout << endl;
}
Problem p00432 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;
int dp[2][10000];
pair<pair<int, int>, pair<int, int>> event[20000];
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b), a) {
    int xm = 0;
    int ym = 0;
    for (int i = 0; i < a; i++) {
      int p, q, r, s;
      scanf("%d%d%d%d", &p, &q, &r, &s);
      event[i * 2] = make_pair(make_pair(p, 1), make_pair(q, s));
      event[i * 2 + 1] = make_pair(make_pair(r, -1), make_pair(q, s));
      xm = max(xm, r);
      ym = max(ym, s);
    }
    std::sort(event, event + a * 2);

    for (int i = 0; i < 2; i++)
      for (int j = 0; j < ym; j++)
        dp[i][j] = 0;
    int S = 0;
    int D = 0;
    int at = 0;
    for (int i = 0; i <= xm; i++) {
      int u = i & 1;
      for (int j = 0; j < ym; j++)
        dp[u][j] = dp[!u][j];
      for (; at < 2 * a && event[at].first.first == i; at++) {
        for (int j = event[at].second.first; j < event[at].second.second; j++)
          dp[u][j] += event[at].first.second;
      }
      for (int j = 0; j < ym; j++)
        if (dp[u][j])
          S++;
      for (int j = 0; j < ym; j++)
        if ((dp[u][j] || dp[!u][j]) && !(dp[u][j] && dp[!u][j]))
          D++;
      for (int j = 0; j < ym - 1; j++)
        if ((dp[u][j] || dp[u][j + 1]) && !(dp[u][j] && dp[u][j + 1]))
          D++;
      if (dp[u][0])
        D++;
      if (dp[u][ym - 1])
        D++;
    }
    printf("%d\\n", S);
    if (b == 2)
      printf("%d\\n", D);
  }
}

Error: MLE

Fixed submission:

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

int g[10003][10003];
int n, r;

int main() {
  while (scanf("%d%d", &n, &r), n) {
    memset(g, 0, sizeof(g));
    int mx = 10001, Mx = 1, my = 10001, My = 1;
    for (int i = 0; i < n; i++) {
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      a++;
      b++;
      c++;
      d++;
      g[a][b]++;
      g[a][d]--;
      g[c][b]--;
      g[c][d]++;
      mx = min(mx, a);
      Mx = max(Mx, c);
      my = min(my, b);
      My = max(My, d);
    }

    for (int i = mx; i <= Mx; i++) {
      int t = 0;
      for (int j = my; j <= My; j++) {
        t += g[i][j];
        g[i][j] = t;
      }
    }

    int s = 0;
    for (int j = my; j <= My; j++) {
      int t = 0;
      for (int i = mx; i <= Mx; i++) {
        t += g[i][j];
        if (g[i][j] = t)
          s++;
      }
    }
    printf("%d\\n", s);

    if (r == 2) {
      int l = 0;
      for (int i = mx; i <= Mx; i++) {
        for (int j = my; j <= My; j++) {
          if (g[i][j]) {
            l += !g[i - 1][j] + !g[i + 1][j] + !g[i][j - 1] + !g[i][j + 1];
          }
        }
      }
      printf("%d\\n", l);
    }
  }
  return 0;
}
Problem p00432 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

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

int a[2][10010];
vector<pair<pair<int, int>, int>> v;

int main() {
  while (true) {
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;
    memset(a, 0, sizeof(a));
    v.clear();
    rep(i, n) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      ++x1, ++y1, ++x2, ++y2;
      v.push_back(make_pair(make_pair(y1, x1), -1));
      v.push_back(make_pair(make_pair(y1, x2), 1));
      v.push_back(make_pair(make_pair(y2, x1), 1));
      v.push_back(make_pair(make_pair(y2, x2), -1));
    }
    sort(v.begin(), v.end());
    int res1 = 0, res2 = 0;
    int t = 0;
    rep(i, 10010) {
      rep(j, 10010) a[1][j] = 0;
      for (; t < (int)v.size(); ++t) {
        if (v[t].first.first != i)
          break;
        a[1][v[t].first.second] -= v[t].second;
      }
      rep(j, 10009) a[1][j + 1] += a[1][j];
      rep(j, 10010) a[1][j] += a[0][j];
      rep(j, 10010) if (a[1][j])++ res1;
      if (r == 2)
        rep(j, 10009) if (j > 0) {
          if (!a[0][j] != !a[1][j])
            ++res2;
          if (!a[1][j] != !a[1][j - 1])
            ++res2;
        }
      rep(j, 10010) a[0][j] = a[1][j];
    }
    cout << res1 << endl;
    if (r == 2)
      cout << res2 << endl;
  }
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

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

int a[10010][10010];

int main() {
  while (true) {
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;
    memset(a, 0, sizeof(a));
    rep(i, n) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      ++x1, ++y1, ++x2, ++y2;
      ++a[x1][y1];
      --a[x1][y2];
      --a[x2][y1];
      ++a[x2][y2];
    }
    rep(i, 10005) rep(j, 10005) a[i][j + 1] += a[i][j];
    rep(i, 10005) rep(j, 10005) a[i + 1][j] += a[i][j];
    int res = 0;
    rep(i, 10005) rep(j, 10005) if (a[i][j])++ res;
    cout << res << endl;
    if (r == 2) {
      res = 0;
      int dx[] = {1, 0, -1, 0};
      int dy[] = {0, 1, 0, -1};
      rep(i, 10005) rep(j, 10005) if (a[i + 1][j + 1])
          rep(k, 4) if (!a[i + dy[k] + 1][j + dx[k] + 1])++ res;
      cout << res << endl;
    }
  }
}
Problem p00433 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b, c = 0, d = 0;
  for (int i = 0; i < 4; i++) {
    cin >> a;
    c = c + a;
  }
  for (int i = 0; i < 4; i++) {
    cin >> b;
    d = d + b;
  }
  if (c < d)
    cout << d << endl;
  else {
    cout << c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (true) {
    int a, b, c = 0, d = 0;
    for (int i = 0; i < 4; i++) {
      cin >> a;
      c = c + a;
    }
    for (int i = 0; i < 4; i++) {
      cin >> b;
      d = d + b;
    }
    if (c < d)
      cout << d << endl;
    else {
      cout << c << endl;
    }
  }
  return 0;
}
Problem p00433 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int a1, a2, a3, a4, b1, b2, b3, b4, s, s1;
  scanf("%d %d %d %d", &a1, &a2, &a3, &a4);
  scanf("%d %d %d %d", &b1, &b2, &b3, &b4);
  s = a1 + a2 + a3 + a4;
  s1 = b1 + b2 + b3 + b4;
  if (s >= s1) {
    printf("%d\\n", s);
  } else if (s < s1) {
    printf("%d\\n", s1);
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int s, ss, sss;
  while (1) {
    scanf("%d", &s);
    if (s == 0)
      break;
    ss = 1000 - s;
    sss = ss / 500;

    ss = ss % 500;
    sss += ss / 100;

    ss = ss % 100;
    sss += ss / 50;

    ss = ss % 50;
    sss += ss / 10;

    ss = ss % 10;
    sss += ss / 5;

    ss = ss % 5;
    sss += ss / 1;

    printf("%d\\n", sss);
  }
  return 0;
}
Problem p00433 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {

  int s[4], t[4], ss, st;

  ss = st = 0;
  for (int i = 0; i < 4; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < 4; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < 4; i++) {
    ss += s[i];
    st += t[i];
  }
  cout << (ss >= st ? ss : st) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int s[5], t[5], ss, st;

  while (1) {
    ss = st = 0;
    for (int i = 0; i < 4; i++) {
      cin >> s[i];
    }
    for (int i = 0; i < 4; i++) {
      cin >> t[i];
    }
    for (int i = 0; i < 4; i++) {
      ss += s[i];
      st += t[i];
    }
    if (ss >= st)
      cout << ss << endl;
    else
      cout << st << endl;
  }

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

#include <stdio.h>

int main(void) {
  int point[4];
  int i;
  int sum[2], max = 0;

  sum[0] = 0;
  sum[1] = 0;

  for (i = 0; i < 2; i++) {
    scanf("%d %d %d %d", &point[0], &point[1], &point[2], &point[3]);
    sum[i] += point[0] + point[1] + point[2] + point[3];
    if (max < sum[i]) {
      max = sum[i];
    }
  }

  printf("%d\\n", max);

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int point[4];
  int i;
  int sum[2], max = 0;

  sum[0] = 0;
  sum[1] = 0;

  for (i = 0; i < 2; i++) {
    scanf("%d %d %d %d", &point[0], &point[1], &point[2], point[3]);
    sum[i] += point[0] + point[1] + point[2] + point[3];
    if (max < sum[i]) {
      max = sum[i];
    }
  }

  printf("%d\\n", max);

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

#include <bits/stdc++.h>
using namespace std;
int S, T, a, i, j;
int main() {
  for (j = 0; j < 4; j++) {
    cin >> a;
    S += a;
  }
  for (j = 0; j < 4; j++) {
    cin >> a;
    T += a;
  }
  cout << max(S, T) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int S, T, a, i, j;
  while (true) {
    S = 0;
    T = 0;
    for (j = 0; j < 4; j++) {
      cin >> a;
      S += a;
    }
    for (j = 0; j < 4; j++) {
      cin >> a;
      T += a;
    }
    cout << max(S, T) << endl;
  }
}
Problem p00433 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;
int main(void) {
  int a = 0, b = 0, c;
  for (int i = 0; i < 4; i++) {
    scanf("%d", &c);
    a += c;
  }

  for (int i = 0; i < 4; i++) {
    scanf("%d", &c);
    b += c;
  }
  if (a > b)
    printf("%d\\n", a);
  else
    printf("%d\\n", b);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
using namespace std;
int main(void) {
  int a = 0, b = 0, c;
  for (int i = 0; i < 4; i++) {
    scanf("%d", c);
    a += c;
  }

  for (int i = 0; i < 4; i++) {
    scanf("%d", c);
    b += c;
  }
  if (a > b)
    printf("%d\\n", a);
  else
    printf("%d\\n", b);
  return 0;
}
Problem p00433 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int sum1 = 0, sum2 = 0, a1, a2;
  for (int i = 0; i < 4; i++) {
    cin >> a1;
    sum1 += a1;
  }
  for (int i = 0; i < 4; i++) {
    cin >> a2;
    sum2 += a2;
  }

  if (sum1 >= sum2) {
    cout << sum1 << endl;
  } else {
    cout << sum2 << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int sum1 = 0, sum2 = 0, a1, a2;
    for (int i = 0; i < 4; i++) {
      cin >> a1;
      sum1 += a1;
    }
    for (int i = 0; i < 4; i++) {
      cin >> a2;
      sum2 += a2;
    }

    if (a1 >= a2) {
      cout << sum1 << endl;
    } else {
      cout << sum2 << endl;
    }
  }
}
Problem p00433 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  int v[4] = {};
  REP(i, 2) {
    REP(j, 4) {
      int a;
      cin >> a;
      v[i] += a;
    }
  }
  cout << max(v[0], v[1]) << endl;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  int v[] = {};
  REP(i, 2) {
    REP(j, 4) {
      int a;
      cin >> a;
      v[i] += a;
    }
  }
  cout << max(v[0], v[1]) << endl;
}
Problem p00433 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int a, b, c, d, e, f, g, h, i, j;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  scanf("%d %d %d %d", &e, &f, &g, &h);
  i = a + b + c + d;
  j = e + f + g + h;
  if (i == j) {
    printf("%d\\n", i);
  } else if (i < j) {
    printf("%d\\n", j);
  } else if (i > j) {
    printf("%d\\n", i);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int a, b, c, d, e, f, g, h, i, j;
  while (1) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    scanf("%d %d %d %d", &e, &f, &g, &h);
    i = a + b + c + d;
    j = e + f + g + h;
    if (i == j) {
      printf("%d\\n", i);
    } else if (i < j) {
      printf("%d\\n", j);
    } else if (i > j) {
      printf("%d\\n", i);
      return 0;
    }
  }
}
Problem p00434 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a[31];
  int d;
  // while(cin>>d){
  for (int i = 0; i <= 30; i++)
    a[i] = 0;
  for (int i = 0; i < 28; i++) {
    cin >> d;
    a[d] = 1;
    // if(i!=27)cin>>d;
  }
  for (int i = 1; i <= 30; i++) {
    if (a[i] == 0)
      cout << i << endl;
  }
  // for(int i = 1 ; i <= 30 ; i++) cout<<a[d]<<endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  bool a[31];
  while (1) {
    for (int i = 0; i < 30; i++)
      a[i] = false;
    int d;
    for (int i = 0; i < 28; i++) {
      cin >> d;
      a[d] = true;
    }
    for (int i = 1; i <= 30; i++) {
      if (a[i] == false)
        cout << i << endl;
    }
  }
}
Problem p00434 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
using namespace std;
int main(void) {
  // Your code here!
  int a, tf;
  queue<int> h;
  for (int i = 1; i <= 28; i++) {
    cin >> a;
    h.push(a);
  }
  for (int i = 1; i <= 30; i++) {
    tf = 0;
    for (int i2 = 1; i2 <= 28; i2++) {
      if (h.empty())
        break;
      a = h.front();
      h.pop();
      if (i == a) {
        tf = 1;
        break;
      } else
        h.push(a);
    }
    if (tf == 0)
      cout << i << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;
int main(void) {
  // Your code here!
  int a, tf;
  queue<int> h;
  for (int i = 1; i <= 28; i++) {
    cin >> a;
    h.push(a);
  }
  for (int i = 1; i <= 30; i++) {
    tf = 0;
    for (int i2 = 1; i2 <= 28; i2++) {
      a = h.front();
      h.pop();
      if (i == a) {
        tf = 1;
        break;
      } else
        h.push(a);
    }
    if (tf == 0)
      cout << i << endl;
  }
}
Problem p00434 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a[31] = {}, i, b;
  for (i = 0; i < 28; i++) {
    cin >> b;
    a[b] = 1;
  }
  for (i = 1; i <= 30; i++)
    if (a[i] == 0)
      cout << i << endl;
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <iostream>
using namespace std;
#define N 30
int main() {
  int a[30], i, b;
  for (i = 0; i < N - 2; i++) {
    cin >> b;
    a[b] = 0;
  }
  for (i = 1; i <= N; i++)
    if (a[i] != 0)
      cout << i << endl;
  return 1;
}
Problem p00434 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int b, i, j, k;
  int a[30];
  for (i = 0; i < 30; i++) {
    a[i] = 0;
  }
  for (j = 0; j < 28; j++) {
    cin >> b;
    a[b - 1] = 1;
  }
  for (k = 0; k < 30; k++) {
    if (a[k] == 0) {
      cout << k + 1 << endl;
    }
  }
  return 0;
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int b, i, j, k;
  int a[30];
  for (i = 0; i < 30; i++) {
    a[i] = 0;
  }
  for (j = 0; j < 28; j++) {
    cin >> b;
    a[b] = 1;
  }
  for (k = 1; k <= 30; k++) {
    if (a[k] == 0) {
      cout << k << endl;
    }
  }
  return 0;
}