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

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define INF 1 << 20

struct node {
  int kind, h, step;

  node() { this->kind = this->h = this->step = 0; }
  node(int kind, int h, int step) : kind(kind), h(h), step(step) {}
};

int main() {
  int H;
  while (cin >> H, H) {
    vector<vector<int>> state(2, vector<int>(H + 1, 0));
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < H; ++j)
        cin >> state[i][j];

    vector<vector<int>> steps(2, vector<int>(H));
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < H; ++j)
        steps[i][j] = -1;

    int ans = -1;

    queue<node> que;
    que.push(node(0, 0, 0));
    que.push(node(1, 0, 0));
    while (!que.empty()) {
      node n = que.front();
      que.pop();

      if (n.h >= H)
        continue;

      if (state[n.kind][n.h] == 2)
        while (state[n.kind][--n.h] == 2)
          ;

      else if (state[n.kind][n.h] == 1) {
        while (state[n.kind][++n.h] == 1)
          ;
        --n.h;
      }

      if (n.h == H - 1) {
        ans = n.step;
        break;
      }

      if (steps[n.kind][n.h] >= 0)
        continue;
      steps[n.kind][n.h] = n.step;

      que.push(node(!n.kind, n.h, n.step + 1));
      que.push(node(!n.kind, n.h + 1, n.step + 1));
      que.push(node(!n.kind, n.h + 2, n.step + 1));
    }
    if (ans >= 0)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define INF 1 << 20

struct node {
  int kind, h, step;

  node() { this->kind = this->h = this->step = 0; }
  node(int kind, int h, int step) : kind(kind), h(h), step(step) {}
};

int main() {
  int H;
  while (cin >> H, H) {
    vector<vector<int>> state(2, vector<int>(H + 1, 0));
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < H; ++j)
        cin >> state[i][j];

    vector<vector<int>> steps(2, vector<int>(H));
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < H; ++j)
        steps[i][j] = -1;

    int ans = -1;

    queue<node> que;
    que.push(node(0, 0, 0));
    que.push(node(1, 0, 0));
    while (!que.empty()) {
      node n = que.front();
      que.pop();

      if (n.h >= H)
        continue;

      if (state[n.kind][n.h] == 2)
        while (state[n.kind][--n.h] != 2)
          ;

      else if (state[n.kind][n.h] == 1) {
        while (state[n.kind][++n.h] != 1)
          ;
        --n.h;
      }

      if (n.h == H - 1) {
        ans = n.step;
        break;
      }

      if (steps[n.kind][n.h] >= 0)
        continue;
      steps[n.kind][n.h] = n.step;

      que.push(node(!n.kind, n.h, n.step + 1));
      que.push(node(!n.kind, n.h + 1, n.step + 1));
      que.push(node(!n.kind, n.h + 2, n.step + 1));
    }
    if (ans >= 0)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
}
Problem p00230 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int buil[2][103];
bool done[2][103];
int n;

#define INF 1000000000

int bfs() {
  queue<int> q;
  q.push(0);
  q.push(0);
  q.push(0);
  q.push(1);
  q.push(0);
  q.push(0);

  while (!q.empty()) {
    int x = q.front();
    q.pop();
    int y = q.front();
    q.pop();
    int v = q.front();
    q.pop();

    while (y + 1 < n && buil[x][y + 1] && buil[x][y] == 1)
      y++;
    while (buil[x][y] == 2)
      y--;

    if (done[x][y])
      continue;

    if (y == n - 1)
      return v;

    done[x][y] = true;

    if (y + 1 < n) {
      q.push((x + 1) % 2);
      q.push(y + 1);
      q.push(v + 1);
    }

    if (y + 2 < n) {
      q.push((x + 1) % 2);
      q.push(y + 2);
      q.push(v + 1);
    }
  }
  return -1;
}

int main() {
  while (true) {
    for (int i = 0; i < 103; i++)
      done[0][i] = done[1][i] = false;

    cin >> n;
    if (!n)
      break;
    for (int j = 0; j < 2; j++) {
      for (int i = 0; i < n; i++)
        cin >> buil[j][i];
    }
    int res = bfs();
    if (res == -1)
      cout << "NA" << endl;
    else
      cout << res << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int buil[2][103];
int mem[2][103];
bool done[2][103];
int n;

#define INF 1000000000

int dfs(int x, int y) {
  while (buil[x][y + 1] == 1 && buil[x][y])
    y++;
  while (buil[x][y] == 2)
    y--;
  if (y == n - 1)
    return 0;

  if (done[x][y] || y >= n)
    return INF;
  done[x][y] = true;

  mem[x][y] = min(dfs((x + 1) % 2, y + 2), dfs((x + 1) % 2, y + 1)) + 1;
  done[x][y] = false;
  return mem[x][y];
}

int main() {
  while (true) {
    cin >> n;
    if (!n)
      break;
    for (int j = 0; j < 2; j++) {
      for (int i = 0; i < n; i++)
        cin >> buil[j][i];
    }
    int res = min(dfs(0, 0), dfs(1, 0));
    if (res >= INF)
      cout << "NA" << endl;
    else
      cout << res << endl;
  }
}
Problem p00230 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int a[2][105];
int visit[2][105];

int main() {
  int n;
  while (cin >> n, n) {
    memset(a, 0, sizeof(a));
    memset(visit, 0, sizeof(visit));
    rep(k, 2) rep(i, n) cin >> a[k][i];
    rep(k, 2) rep(i, 105) visit[k][i] = 0;

    priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> q;
    q.push(MP(0, MP(0, 0)));
    q.push(MP(0, MP(1, 0)));
    int ans = -1;
    while (!q.empty()) {
      P p = q.top().second;
      int d = q.top().first;
      q.pop();

      while (a[p.X][p.Y] == 1 && a[p.X][p.Y + 1] == 1)
        p.Y++;
      while (a[p.X][p.Y] == 2)
        p.Y--;
      if (visit[p.X][p.Y])
        continue;
      visit[p.X][p.Y] = 1;
      if (p.Y >= n - 1) {
        ans = d;
        break;
      }

      rep(i, 3) {
        int nx = !p.X;
        int ny = p.Y + i;
        if (ny >= n)
          ny = n - 1;
        q.push(MP(d + 1, MP(nx, ny)));
      }
    }
    if (ans != -1)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int a[2][105];
int dist[2][105];

int main() {
  int n;
  while (cin >> n, n) {
    rep(k, 2) rep(i, n) cin >> a[k][i];
    rep(k, 2) rep(i, 105) dist[k][i] = 1 << 29;

    priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> q;
    q.push(MP(0, MP(0, 0)));
    q.push(MP(0, MP(1, 0)));
    dist[0][0] = 0;
    dist[1][0] = 0;
    int ans = 0;
    while (!q.empty()) {
      P p = q.top().second;
      int d = q.top().first;
      q.pop();

      if (dist[p.X][p.Y] != d)
        continue;
      if (p.Y >= n) {
        ans = d;
        break;
      }

      rep(i, 3) {
        int nx = !p.X;
        int ny = p.Y + i;
        while (a[nx][ny] == 1 && a[nx][ny + 1] == 1)
          ny++;
        while (a[nx][ny] == 2)
          ny--;
        if (dist[nx][ny] < d + 1)
          continue;
        dist[nx][ny] = d + 1;
        q.push(MP(d + 1, MP(nx, ny)));
      }
    }
    if (ans)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }

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

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
int n;
int mas[2][222];
bool used[2][222];
struct P {
  int a, b, c;
}; // a=棟 b=階 c=cnt
int bfs();
int main() {
  while (1) {
    memset(mas, 0, sizeof(mas));
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> mas[0][i];
    for (int i = 0; i < n; i++)
      cin >> mas[1][i];
    memset(used, 0, sizeof(used));
    int k = bfs();
    if (k == -1)
      cout << "NA" << endl;
    else
      cout << k << endl;
  }
}
int bfs() {
  queue<P> que;
  P p = {0, 0, 0};
  que.push(p);
  p.a = 1;
  que.push(p);
  while (!que.empty()) {
    P p = que.front();

    for (;; p.b++) {
      if (!(mas[p.a][p.b] == 1 && mas[p.a][p.b + 1] == 1))
        break;
    }
    for (;; p.b--) {
      if (!(mas[p.a][p.b] == 2))
        break;
    }

    if (p.b == n - 1)
      return p.c;
    que.pop();
    if (used[p.a][p.b]++)
      continue;
    for (int i = 0; i < 3; i++) {
      if (p.b + i < n) {
        P HM = {(p.a == 0 ? 1 : 0), p.b + i, p.c + 1};
        que.push(HM);
      }
    }
  }
  return -1;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
int n;
int mas[2][222];
struct P {
  int a, b, c;
}; // a=棟 b=階 c=cnt
int bfs();
int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> mas[0][i];
    for (int i = 0; i < n; i++)
      cin >> mas[1][i];
    cout << bfs() << endl;
  }
}
int bfs() {
  queue<P> que;
  P p = {0, 0, 0};
  que.push(p);
  p.a = 1;
  que.push(p);
  while (!que.empty()) {
    P p = que.front();
    for (;; p.b++) {
      if (!(mas[p.a][p.b] == 1 && mas[p.a][p.b + 1] == 1))
        break;
    }
    for (;; p.b--) {
      if (!(mas[p.a][p.b] == 2))
        break;
    }
    if (p.b == n - 1)
      return que.front().c;
    que.pop();
    for (int i = 0; i < 3; i++) {
      if (p.b + i < n) {
        P HM = {(p.a == 0 ? 1 : 0), p.b + i, p.c + 1};
        que.push(HM);
      }
    }
  }
  return -1;
}
Problem p00230 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int inf = 1e8;

int building[2][1000];
bool visited[2][1000];
int n;
int solve(int t) {
  memset(visited, false, sizeof(visited));
  queue<pair<pair<int, int>, int>> q;
  q.push(make_pair(make_pair(t, 0), 0));
  while (!q.empty()) {
    pair<pair<int, int>, int> p = q.front();
    q.pop();
    int x = p.first.first, y = p.first.second, count = p.second;
    if (visited[x][y])
      continue;
    visited[x][y] = true;

    if (building[x][y] == 2)
      while (building[x][y] == 2)
        y--;
    if (building[x][y] == 1)
      while (building[x][y] == 1 && building[x][y + 1] == 1)
        y++;

    if (y == n - 1)
      return count;
    for (int i = 0; i < 3; i++) {
      if (y + i < n)
        q.push(make_pair(make_pair(!x, y + i), count + 1));
    }
  }
  return inf;
}

int main() {
  while (cin >> n, n) {
    memset(building, 0, sizeof(building));
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < n; j++)
        cin >> building[i][j];
    int ret = min(inf, min(solve(0), solve(1)));
    if (ret == inf)
      cout << "NA" << endl;
    else
      cout << ret << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const double inf = (int)1e8;

int building[2][1000];
bool b[2][1000];
int n;

int climb(int x, int y, int count) {
  int ret = inf;
  if (building[x][y] == 2)
    while (building[x][y] == 2)
      y--;
  if (building[x][y] == 1) {
    while (building[x][y] == 1)
      y++;
    y--;
  }
  if (y == n - 1)
    return count;
  if (!b[x][y])
    return inf;
  b[x][y] = false;
  for (int i = 0; i < 3 && y + i < n; i++) {
    ret = min(ret, climb((x + 1) % 2, y + i, count + 1));
  }
  b[x][y] = true;
  return ret;
}

int main() {
  while (cin >> n, n) {
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 1000; j++) {
        building[i][j] = 0;
        b[i][j] = true;
      }
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < n; j++)
        cin >> building[i][j];
    int ret = inf;
    for (int i = 0; i < 2; i++)
      ret = min(climb(i, 0, 0), ret);
    if (ret == inf)
      cout << "NA" << endl;
    else
      cout << ret << endl;
  }
}
Problem p00231 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
using namespace std;
#define START 0
#define END 1

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    multimap<int, pair<int, int>> M;
    for (int i = 0; i < n; ++i) {
      int m, a, b;
      scanf("%d%d%d", &m, &a, &b);
      M.insert(make_pair(a, make_pair(START, m)));
      M.insert(make_pair(b, make_pair(END, m)));
    }

    int total = 0;
    bool ng = false;
    for (map<int, pair<int, int>>::iterator itm = M.begin(); itm != M.end();
         ++itm) {
      int t = itm->first;
      while (t == itm->first) {
        if (itm->second.first == START) {
          total += itm->second.second;
        } else {
          total -= itm->second.second;
        }
        ++itm;
        if (itm == M.end())
          break;
      }
      if (total > 150) {
        ng = true;
      }
      --itm;
    }

    if (ng) {
      puts("NG");
    } else {
      puts("OK");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;
#define START 0
#define END 1

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    multimap<int, pair<int, int>> M;
    for (int i = 0; i < n; ++i) {
      int m, a, b;
      scanf("%d%d%d", &m, &a, &b);
      M.insert(make_pair(a, make_pair(START, m)));
      M.insert(make_pair(b, make_pair(END, m)));
    }

    int total = 0;
    bool ng = false;
    for (map<int, pair<int, int>>::iterator itm = M.begin(); itm != M.end();
         ++itm) {
      int t = itm->first;
      while (t == itm->first) {
        if (itm->second.first == START) {
          total += itm->second.second;
        } else {
          total -= itm->second.second;
        }
        ++itm;
      }
      if (total > 150) {
        ng = true;
      }
      --itm;
    }

    if (ng) {
      puts("NG");
    } else {
      puts("OK");
    }
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> p;
typedef pair<int, p> P; // time,which,weight
int main() {
  P t[300];
  int n, a, b, c;
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      t[i].second.second = a;
      t[i].first = b;
      t[i].second.first = 1;
      t[i + n].second.second = a;
      t[i + n].first = c;
      t[i + n].second.first = 0;
    }
    int now = 0;
    sort(t, t + 2 * n);
    for (int i = 0; i < 2 * n; i++) {

      if (t[i].second.first)
        now += t[i].second.second;
      else
        now -= t[i].second.second;

      if (now > 150) {
        cout << "NG" << endl;
        goto end;
      }
    }

    cout << "OK" << endl;

  end:;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> p;
typedef pair<int, p> P; // time,which,weight
int main() {
  P t[101];
  int n, a, b, c;
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      t[i].second.second = a;
      t[i].first = b;
      t[i].second.first = 1;
      t[i + n].second.second = a;
      t[i + n].first = c;
      t[i + n].second.first = 0;
    }
    int now = 0;
    sort(t, t + 2 * n);
    for (int i = 0; i < 2 * n; i++) {

      if (t[i].second.first)
        now += t[i].second.second;
      else
        now -= t[i].second.second;

      if (now > 150) {
        cout << "NG" << endl;
        goto end;
      }
    }

    cout << "OK" << endl;

  end:;
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define MAX 150

using namespace std;

struct DATA {
  int time;
  int log;
};

bool IsSafety(vector<DATA>);
bool Compare(const DATA &, const DATA &);

int main() {
  int i, n, m, a, b;
  DATA _data;
  vector<DATA> data;

  while (1) {
    cin >> n;
    if (n == 0)
      break;

    for (i = 0; i < n; ++i) {
      cin >> m >> a >> b;
      _data.time = a;
      _data.log = m;
      data.push_back(_data);
      _data.time = b;
      _data.log = -m;
      data.push_back(_data);
    }

    sort(data.begin(), data.end(), Compare);

    if (IsSafety(data))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;

    data.clear();
  }
  return 0;
}

bool IsSafety(vector<DATA> data) {
  int i, sum;
  for (i = 0, sum = 0; i < data.size(); ++i) {
    sum += data[i].log;
    if (sum > MAX)
      return false;
  }
  return true;
}

bool Compare(const DATA &x, const DATA &y) {
  if (x.time == y.time)
    return x.log < y.log;
  else
    return x.time < y.time;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>
#define M 150

using namespace std;

int Case1(vector<int> &, int, int, int);
int Case2(vector<int> &, int, int, int);
int Case3(vector<int> &, int, int, int);

int main() {
  int i, n, m, a, b, x;
  vector<int> data;

  while (1) {
    cin >> n;
    if (n == 0)
      break;

    for (i = 0, x = 0; i < n; ++i) {
      cin >> m >> a >> b;
      if (x == 0) {
        if (b <= data.size())
          x = Case1(data, a - 1, b - 1, m);
        else if (a < data.size())
          x = Case2(data, a - 1, b - 1, m);
        else
          x = Case3(data, a - 1, b - 1, m);
      }
    }

    if (x == 1)
      cout << "NG" << endl;
    else
      cout << "OK" << endl;

    data.clear();
  }
  return 0;
}

int Case1(vector<int> &data, int a, int b, int n) {
  int i;
  for (i = a; i < b; ++i) {
    data[i] += n;
    if (data[i] > M)
      return 1;
  }
  return 0;
}

int Case2(vector<int> &data, int a, int b, int n) {
  int i;
  for (i = a; i < data.size(); ++i) {
    data[i] += n;
    if (data[i] > M)
      return 1;
  }
  for (i = data.size(); i < b; ++i)
    data.push_back(n);
  return 0;
}

int Case3(vector<int> &data, int a, int b, int n) {
  int i;
  for (i = data.size(); i < a; ++i)
    data.push_back(0);
  for (i = a; i < b; ++i)
    data.push_back(n);
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int n, m[100], a[100], b[100];
bool ans;

int main(void) {

  while (cin >> n, n) {

    for (int i = 0; i < n; i++) {
      cin >> m[i] >> a[i] >> b[i];
    }

    ans = false;
    for (int i = 0; i < n; i++) {
      int c = m[i];
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (a[j] <= a[i] && a[i] < b[j])
          c += m[j];
      }
      // 時間ないのところ全てに m を加えていく
      if (c > 150) {
        ans = true;
        break;
      }
    }
    if (ans)
      cout << "NG" << endl;
    else
      cout << "OK" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int n, m, a, b;
int t[101];
int x;

bool compute(void) {

  for (int i = 0; i < 100; i++) {
    if (t[i] > 150)
      return false;
  }
  return true;
}

int main(void) {

  while (cin >> n, n) {

    for (int i = 0; i <= 100; i++)
      t[i] = 0;

    for (int i = 0; i < n; i++) {
      cin >> m >> a >> b;
      x = max(x, b);
      for (int j = a; j < b; j++) {
        t[j] += m;
      }
    }
    if (compute())
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 99999999

int main() {
  int n, a, b, c;
  while (cin >> n && n) {
    vector<pii> v;
    rep(i, n) {
      cin >> a >> b >> c;
      v.pb(pii(b, a));
      v.pb(pii(c, -a));
    }
    sort(all(v));
    int sum = 0;
    bool f = false;
    rep(i, v.size()) {
      sum += v[i].second;
      if (sum > 150) {
        f = true;
        break;
      }
    }
    if (f)
      cout << "NG" << endl;
    else
      cout << "OK" << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#define rep(a, b, c) for (int a = b; a < c; a++)

using namespace std;

int brid[1ULL << 10] = {};

int main() {
  int n;
  while ((cin >> n)) {
    if (n == 0)
      break;
    int w[101], s[101], e[101];
    rep(i, 0, n) {
      cin >> w[i] >> s[i] >> e[i];
      brid[s[i]] += w[i];
      brid[e[i]] -= w[i];
    }
    for (int i = 0; i < 1ULL << 10; i++) {
      int now = 0;
      now += brid[i];
      if (now > 150) {
        cout << now << endl;
        cout << "NG" << endl;
        goto end;
      }
    }
    cout << "OK" << endl;
  end:;
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>
typedef struct {
  int x, value;
} data;
data d[200];
int cd;
int comp(const void *a, const void *b) {
  data *p = (data *)a;
  data *q = (data *)b;
  if (p->x == q->x) {
    if (p->value < 0)
      return 0;
    else if (q->value < 0)
      return 1;
  }
  return p->x - q->x;
}
int main() {
  int n;
  int m, a, b;
  int i;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    cd = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &m, &a, &b);
      d[cd].x = a;
      d[cd].value = m;
      cd++;
      d[cd].x = b;
      d[cd].value = -m;
      cd++;
    }
    qsort(d, 2 * n, sizeof(data), comp);
    int k = 0;
    for (i = 0; i < 2 * n; i++) {
      k += d[i].value;
      if (k > 150)
        break;
    }
    if (i == 2 * n)
      printf("OK\\n");
    else
      printf("NG\\n");
  }
}


Error: WA

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
typedef struct {
  int x, value;
} data;
data d[200];
int cd;
int comp(const void *a, const void *b) {
  data *p = (data *)a;
  data *q = (data *)b;
  return p->x - q->x;
}
int main() {
  int n;
  int m, a, b;
  int i;
  cd = 0;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &m, &a, &b);
      d[cd].x = a;
      d[cd].value = m;
      cd++;
      d[cd].x = b;
      d[cd - 1].value = -m;
      cd++;
    }
    qsort(d, 2 * n, sizeof(data), comp);
    int k = 0;
    for (i = 0; i < 2 * n; i++) {
      k += d[i].value;
      if (k > 150)
        break;
    }
    if (i == 2 * n)
      printf("OK\\n");
    else
      printf("NG\\n");
  }
}