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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a;
  while (cin >> a, a) {
    vector<vector<int>> s;
    for (int b = 0; b < a; b++) {
      vector<int> c(3);
      cin >> c[0] >> c[1] >> c[2];
      s.push_back(c);
    }
    for (int d = 0; d < s.size(); d++) {
      int n = 0;
      for (int e = 0; e < s.size(); e++) {
        if (s[d][1] >= s[e][1] && s[d][1] < s[e][2])
          n += s[e][0];
      }
      if (n > 150) {
        cout << "NG" << endl;
        break;
      }
      if (s.size() - 1 == d) {
        cout << "OK" << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int a;
    cin >> a;
    if (a == 0)
      break;
    vector<vector<int>> s(a);
    int m = 0;
    for (int b = 0; b < a; b++) {
      vector<int> p(3);
      int c, d, e;
      cin >> c >> d >> e;
      if (e > m)
        m = e;
      p[0] = c;
      p[1] = d;
      p[2] = e;
      s[b] = p;
    }
    for (int u = 0; u < m; u++) {
      int k = 0;
      for (int h = 0; h < a; h++) {
        if (s[h][1] <= u && s[h][2] > u)
          k += s[h][0];
      }
      if (k > 150) {
        cout << "NG" << endl;
        break;
      }
      if (m - 1 == u) {
        cout << "OK" << endl;
        break;
      }
    }
  }
}
Problem p00231 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
// #include <fstream>	// require freopen

using namespace std;

struct D {
  int m;
  int a;
  int b;
};

int main() {
  //	cut here before submit
  //	freopen ("testcase.db", "r", stdin );
  int n;

  while (cin >> n && n) {
    vector<D> d(n);
    int m, a, b;
    int i, j;

    for (i = 0; i < n; ++i) {
      cin >> m >> a >> b;
      d[i].m = m;
      d[i].a = a;
      d[i].b = b;
    } // end for

    bool break_bridge = false;

    for (i = 0; i < n; ++i) {
      int sum = d[i].m;
      for (j = 0; j < n; ++j) {
        if (i != j && d[i].a >= d[j].a && d[i].a < d[j].b) {
          sum += d[j].m;
        } // end if
      }   // end for
      if (sum > 150) {
        break_bridge = true;
        break;
      } // end if
    }   // end for

    if (!break_bridge) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    } // end if
  }   // end while

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
// #include <cstring>	// require memset
// #include <fstream>	// require freopen

using namespace std;

// int t[101][231];

int main() {
  //	cut here before submit
  //	freopen ("testcase.db", "r", stdin );
  int n;
  vector<bool> res;

  while (cin >> n && n) {
    //		memset (t, 0, sizeof (t ) );
    vector<vector<int>> t(n, vector<int>(231, 0));
    int m, a, b;
    int i, j;

    for (i = 0; i < n; ++i) {
      cin >> m >> a >> b;
      for (j = a; j < b; ++j) {
        t[i][j] = m;
      } // end for
    }   // end for

    bool break_bridge = false;

    for (j = 0; j <= 230; ++j) {
      int sum = 0;
      for (i = 0; i < n; ++i) {
        sum += t[i][j];
      } // end for
      if (sum > 150) {
        break_bridge = true;
        break;
      } // end if
    }   // end for
    res.push_back(break_bridge);
  } // end while

  for (int i = 0; i < res.size(); ++i) {
    bool break_bridge = res[i];
    if (!break_bridge) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    } // end if
  }   // end loop

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>

using namespace std;

signed int S[100003] = {}, L[100003] = {};
int N[100000] = {};

int main() {
  int n, m;
  while (10) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> N[i] >> S[i] >> L[i];
    }
    bool f = 1;
    for (int i = 0; i < n; i++) {
      int g = 0;
      for (int j = 0; j < n; j++) {
        if (i == j)
          g += N[i];
        else if (S[j] <= S[i] && S[i] < L[j])
          g += N[j];
        if (g > 150)
          f = 0;
        if (f == 0)
          break;
      }
      // cout<<g;
      if (f == 0)
        break;
    }
    if (f)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {

  int n[102] = {};

  int N;
  int m, a, b;

  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;
    bool f = false;
    for (int i = 0; i < N; i++) {
      scanf("%d %d %d", &m, &a, &b);
      for (int j = a; j < b; j++) {
        n[j] += m;
        if (n[j] > 150)
          f = true;
      }
    }

    // for(int i=0;i<101;i++)
    //	if(n[i]>150)printf("%d\\n",i);

    if (f == true)
      printf("NG\\n");
    else
      printf("OK\\n");

    for (int i = 0; i < 101; i++)
      n[i] = 0;
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <string>
#include <vector>

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

using namespace std;

struct Time {
  int t, cost;

  Time(int _t, int _cost) {
    t = _t;
    cost = _cost;
  }

  bool operator<(const Time &ti) const { return t < ti.t; }
};

int main() {
  int n;
  while (cin >> n && n) {
    map<int, int> ma;

    rep(i, n) {
      int m, a, b;
      cin >> m >> a >> b;

      ma[a] += m;
      ma[b] -= m;
    }

    vector<Time> v;
    map<int, int>::iterator ite;
    for (ite = ma.begin(); ite != ma.end(); ite++) {
      v.push_back(Time(ite->first, ite->second));
    }

    sort(v.begin(), v.end());
    vector<int> res;
    res.resize(v.size());

    int temp = 0;

    rep(i, v.size()) {
      temp += v[i].cost;
      res[i] = temp;
    }

    bool flag = true;
    rep(i, res.size()) {
      if (res[i] > 150)
        flag = false;
    }

    if (flag)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <string>
#include <vector>

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

using namespace std;

int main() {
  int n;
  while (cin >> n && n) {
    map<int, int> ma;
    int mt = 0;

    rep(i, n) {
      int m, a, b;
      cin >> m >> a >> b;

      ma[a] += m;
      ma[b] -= m;

      mt = max(mt, b);
    }

    rep(i, mt + 1) { ma[i + 1] += ma[i]; }

    bool flag = true;
    rep(i, mt + 1) {
      if (ma[i] > 150) {
        flag = false;
        break;
      }
    }

    if (flag)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }

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

#include <iostream>
#include <map>

int n, m, a, b, w;

int main() {
  std::map<int, int> br;
  std::map<int, int>::iterator it;
  while (true) {
    std::cin >> n;
    if (!n)
      return 0;
    for (int i = 0; i < n; i++) {
      std::cin >> m >> a >> b;
      if (br.find(a) == br.end())
        br[a] = 0;
      if (br.find(b) == br.end())
        br[b] = 0;
      br[a] += m;
      br[b] -= m;
    }
    it = br.begin();
    int w = 0;
    while (it != br.end()) {
      w += (*it).second;
      if (w > 150) {
        std::cout << "NG\\n";
        break;
      }
      it++;
    }
    if (it == br.end())
      std::cout << "OK\\n";
    br.clear();
  }
}

Error: 0

Fixed submission:

#include <iostream>

int br[232];
int n, m, a, b, w;

bool solve() {
  for (int i = 0; i < 232; i++)
    br[i] = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> m >> a >> b;
    br[a] += m;
    br[b] -= m;
  }
  w = 0;
  for (int i = 0; i < 232; i++) {
    w += br[i];
    if (w > 150)
      return false;
  }
  return true;
}

int main() {
  while (true) {
    std::cin >> n;
    if (!n)
      return 0;
    if (solve())
      std::cout << "OK\\n";
    else
      std::cout << "NG\\n";
  }
}
Problem p00231 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <utility>
#include <vector>
#define INF 2147483647

using namespace std;

int main() {
  int n, x;
  int m[105], a[105], b[105];
  int tmp;
  int j, k, l;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    x = 0;
    tmp = 0;
    int min_a = INF;
    int min_b = INF;
    j = k = 0;
    for (int i = 0; i < n; i++) {
      cin >> m[i] >> a[i] >> b[i];
      if (b[i] > x) {
        x = b[i];
        l = i;
      }
    }

    while (b[l] != INF) {
      int min_a = INF;
      int min_b = INF;
      for (int i = 0; i < n; i++) {
        if (a[i] < min_a) {
          min_a = a[i];
          j = i;
        }
      }
      for (int i = 0; i < n; i++) {
        if (b[i] < min_b) {
          min_b = b[i];
          k = i;
        }
      }

      if (min_a == min_b) {
        tmp += m[j];
        tmp -= m[k];
        a[j] = b[k] = INF;
      } else if (min_a < min_b) {
        tmp += m[j];
        a[j] = INF;
      } else {
        tmp -= m[k];
        b[k] = INF;
      }
      if (tmp > 150) {
        cout << "NG" << endl;
        goto next;
      }
    }
    cout << "OK" << endl;
  next:;
  }

  return (0);
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, clk, x;
  int m[100], a[100], b[100];
  int tmp;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    x = 0;
    tmp = 0;
    for (int i = 0; i < n; i++) {
      cin >> m[i] >> a[i] >> b[i];
      x = max(b[i], x);
    }
    for (clk = 0; clk <= x; clk++) {
      for (int i = 0; i < n; i++) {
        if (a[i] == clk)
          tmp += m[i];
        if (b[i] == clk)
          tmp -= m[i];
        if (tmp > 150) {
          cout << "NG" << endl;
          goto next;
        }
      }
    }
    cout << "OK" << endl;
  next:;
  }

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

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define no_way 100000000;

int d[400][400];

int main(int argc, char **argv) {
  int n;
  int m, a, b;
  vector<pair<int, int>> v;

  while (cin >> n && n != 0) {
    v.clear();
    bool flag = true;
    int in_cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> m >> a >> b;
      v.push_back(make_pair(a, m));
      v.push_back(make_pair(b, -1 * m));
    }
    sort(v.begin(), v.end());

    int value = 0;
    for (int i = 0; i < v.size(); i++) {
      value += v[i].second;
      if (value > 150) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define no_way 100000000;

int d[400][400];

int main(int argc, char **argv) {
  int n;
  int m, a, b;
  vector<pair<pair<int, int>, int>> v;

  while (cin >> n && n != 0) {
    v.clear();
    bool flag = true;
    int in_cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> m >> a >> b;
      v.push_back(make_pair(make_pair(a, b), m));
    }
    sort(v.rbegin(), v.rend());

    int max = v[0].first.second;
    int value = 0;
    for (int i = 0; i < max; i++) {
      for (int j = 1; j <= in_cnt; j++) {
        if (v[v.size() - j].first.second == i) {
          value -= v[v.size() - j].second;
          in_cnt--;
          j--;
          v.erase(v.end() - 1 - j);
        }
      }
      if (v.size() > 1) {
        if (v[v.size() - 1 - in_cnt].first.first == i) {
          value += v[v.size() - 1 - in_cnt].second;
          in_cnt++;
        }
      } else {
        if (v[0].first.first == i) {
          value += v[v.size() - 1 - in_cnt].second;
          in_cnt++;
        }
      }
      if (value > 150) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

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

#include <stdio.h>

#define W_LIM 150

int main(void) {
  int n;
  int curW;
  int ev[256];
  int evTime[256];
  int evCnt;
  int broken;

  while (scanf("%d", &n), n) {
    evCnt = 0;
    // read events
    for (int i = 0; i < n; i++) {
      int m, a, b;

      scanf("%d %d %d", &m, &a, &b);
      ev[evCnt] = m;
      evTime[evCnt] = a;
      evCnt++;
      ev[evCnt] = -m;
      evTime[evCnt] = b;
      evCnt++;
    }
    // sort eventTable
    for (int i = 0; i < evCnt; i++) {
      int min = i, minT = evTime[i], tmp;
      for (int j = i + 1; j < evCnt; j++) {
        if (evTime[j] < minT)
          minT = evTime[min = j];
      }
      evTime[min] = evTime[i];
      evTime[i] = minT;
      tmp = ev[min];
      ev[min] = ev[i];
      ev[i] = tmp;
    }

    // simulate
    curW = 0;
    broken = 0;
    for (int i = 0; i < evCnt; i++) {
      curW += ev[i];
      //		printf("t:%d  ev:%d  curW:%d\\n", evTime[i], ev[i],
      //curW);
      // ????????????????????????????????????????????????????????§???????????????
      if (evTime[i + 1] == evTime[i])
        continue;
      if (curW > W_LIM)
        broken = 1;
    }
    puts(broken ? "NG" : "OK");
    //		for (int i=0; i<evCnt; i++){
    //			printf("t:%d  ev:%d\\n", evTime[i], ev[i]);
    //		}
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

#define W_LIM 150

int main(void) {
  int n;
  int curW;
  int ev[127];
  int evTime[127];
  int evCnt;
  int broken;

  while (scanf("%d", &n), n) {
    evCnt = 0;
    // read events
    for (int i = 0; i < n; i++) {
      int m, a, b;

      scanf("%d %d %d", &m, &a, &b);
      ev[evCnt] = m;
      evTime[evCnt] = a;
      evCnt++;
      ev[evCnt] = -m;
      evTime[evCnt] = b;
      evCnt++;
    }
    // sort eventTable
    for (int i = 0; i < evCnt; i++) {
      int min = i, minT = evTime[i], tmp;
      for (int j = i + 1; j < evCnt; j++) {
        if (evTime[j] < minT)
          minT = evTime[min = j];
      }
      evTime[min] = evTime[i];
      evTime[i] = minT;
      tmp = ev[min];
      ev[min] = ev[i];
      ev[i] = tmp;
    }

    // simulate
    curW = 0;
    broken = 0;
    for (int i = 0; i < evCnt; i++) {
      curW += ev[i];
      //		printf("t:%d  ev:%d  curW:%d\\n", evTime[i], ev[i],
      //curW);
      // ????????????????????????????????????????????????????????§???????????????
      if (evTime[i + 1] == evTime[i])
        continue;
      if (curW > W_LIM)
        broken = 1;
    }
    puts(broken ? "NG" : "OK");
    //		for (int i=0; i<evCnt; i++){
    //			printf("t:%d  ev:%d\\n", evTime[i], ev[i]);
    //		}
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    vector<pair<int, int>> qs;
    for (int i = 0; i < N; ++i) {
      int m, a, b;
      cin >> m >> a >> b;
      qs.push_back(make_pair(a, m));
      qs.push_back(make_pair(b, -m));
    }
    sort(qs.begin(), qs.end());
    int nw = 0;
    bool ok = true;
    for (int i = 0; i < qs.size(); ++i) {
      nw += qs[i].second;
      if (nw > 150)
        ok = false;
    }
    if (ok) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  while (1) {
    int N;
    cin >> N;
    vector<pair<int, int>> qs;
    for (int i = 0; i < N; ++i) {
      int m, a, b;
      cin >> m >> a >> b;
      qs.push_back(make_pair(a, m));
      qs.push_back(make_pair(b, -m));
    }
    sort(qs.begin(), qs.end());
    int nw = 0;
    bool ok = true;
    for (int i = 0; i < qs.size(); ++i) {
      nw += qs[i].second;
      if (nw > 150)
        ok = false;
    }
    if (ok) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}
Problem p00231 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
bool solve(priority_queue<P, vector<P>, greater<P>> q) {
  int weight = 0;
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    weight += p.second;
    if (weight > 150)
      return false;
  }
  return true;
}

int main() {
  int n;
  while (cin >> n and n) {
    priority_queue<P, vector<P>, greater<P>> q;
    REP(i, n) {
      int m, a, b;
      cin >> m >> a >> b;
      q.push(P(a, m));
      q.push(P(b, -m));
    }

    cout << (solve(q) ? "OK" : "NG") << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (li i = 0; i < (li)(n); i++)
typedef int64_t li;
const li VMAX = 4096, INF = 1000000000;
typedef pair<li, li> P;
typedef pair<P, li> Tuple;

struct edge {
  li to, cap, cost, rev;
};

vector<edge> G[VMAX];
li dist[VMAX];
li prevv[VMAX], preve[VMAX];
li V;

void init() {
  REP(i, V) {
    G[i].clear();
    dist[i] = INF;
    prevv[i] = preve[i] = 0;
  }
}

Tuple T(li begin, li end, li cost) { return Tuple(P(begin, end), -cost); }

void add_edge(li from, li to, li cap, li cost) {
  G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
  G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}

li min_cost_flow(li s, li t, li f) {
  li res = 0;
  while (f > 0) {
    fill(dist, dist + V, INF);
    dist[s] = 0;
    bool update = true;

    while (update) {
      update = false;
      REP(v, V) {
        if (dist[v] == INF)
          continue;
        REP(i, G[v].size()) {
          edge &e = G[v][i];
          if (e.cap > 0 and dist[e.to] > dist[v] + e.cost) {
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v;
            preve[e.to] = i;
            update = true;
          }
        }
      }
    }

    if (dist[t] == INF) {
      return -1;
    }

    li d = f;
    for (li v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * dist[t];
    for (li v = t; v != s; v = prevv[v]) {
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int main() {
  li n;
  while (cin >> n and n) {
    V = 2 * n + 3;
    init();
    vector<Tuple> events;
    REP(k, n) {
      li i, j, w;
      cin >> i >> j >> w;
      events.push_back(T(i, j, w));
    }

    const int SOURCE = 0, SINK = 2, BEGIN = 1;

    add_edge(SOURCE, BEGIN, 2, 0);
    add_edge(BEGIN, SINK, 2, 0);

    REP(i, events.size()) {
      add_edge(BEGIN, 2 * i + 3, 1, 0);
      add_edge(2 * i + 4, SINK, 1, 0);
      add_edge(2 * i + 3, 2 * i + 4, 1, events[i].second);
    }

    REP(i, events.size()) {
      REP(j, events.size()) {
        li end = events[i].first.second;
        li begin = events[j].first.first;
        if (end < begin) {
          add_edge(2 * i + 4, 2 * j + 3, 1, 0);
        }
      }
    }

    li min = -min_cost_flow(SOURCE, SINK, 2);
    cout << min << endl;
  }
}
Problem p00232 (C++) — buggy submission, verdict: Runtime Error

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

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

typedef pair<int, int> P;

int x, y, z, v[4];
P t[100];
double dp[100][5002];

int main(void) {
  while (cin >> x >> y >> z, x) {
    memset(dp, 0, sizeof(dp));
    memset(t, 0, sizeof(t));
    rep(i, x) cin >> v[i];
    rep(i, z) {
      int n, e, a;
      cin >> n >> e >> a;
      t[n].first = e;
      t[n].second = a;
    }

    dp[0][0] = 1.0;

    rep(i, y) {
      rep(j, 4902) {
        rep(k, x) {
          int ni = i + v[k];

          if (t[i].first == 0) {
            dp[ni][j] += dp[i][j] * (1.0 / x);
          } else if (t[i].first == 1) {
            ni += t[i].second;
            dp[ni][j] += dp[i][j] * (1.0 / x);
          } else {
            int nj = (t[i].first == 2 ? j + t[i].second : j - t[i].second);
            if (nj < 0)
              nj = 0;
            dp[ni][nj] += dp[i][j] * (1.0 / x);
          }
        }
      }
    }

    double ans = 0;
    REP(i, y, y + 30) REP(j, 1, 5002) {
      if (dp[i][j] > 0) {
        ans += dp[i][j] * j;
      }
    }
    cout << (int)ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

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

typedef pair<int, int> P;

int x, y, z, v[4];
P t[62];
double dp[62][5002];

int main(void) {
  while (cin >> x >> y >> z, x) {
    memset(dp, 0, sizeof(dp));
    memset(t, 0, sizeof(t));
    rep(i, x) cin >> v[i];
    rep(i, z) {
      int n, e, a;
      cin >> n >> e >> a;
      t[n].first = e;
      t[n].second = a;
    }

    dp[0][0] = 1.0;

    rep(i, y) {
      rep(j, 4902) {
        rep(k, x) {
          int ni = i + v[k];

          if (t[i].first == 0) {
            dp[ni][j] += dp[i][j] * (1.0 / x);
          } else if (t[i].first == 1) {
            ni += t[i].second;
            dp[ni][j] += dp[i][j] * (1.0 / x);
          } else {
            int nj = (t[i].first == 2 ? j + t[i].second : j - t[i].second);
            if (nj < 0)
              nj = 0;
            dp[ni][nj] += dp[i][j] * (1.0 / x);
          }
        }
      }
    }

    double ans = 0;
    REP(i, y, y + 21) REP(j, 1, 5002) {
      if (dp[i][j] > 0) {
        ans += dp[i][j] * j;
      }
    }
    cout << (int)ans << endl;
  }

  return 0;
}