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

#include <algorithm>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int M, T, P, R, m, t, p, j;
  while (cin >> M >> T >> P >> R, M || T || P || R) {
    vector<vector<pair<int, int>>> data(
        T + 1, vector<pair<int, int>>(P + 1, pair<int, int>(0, 0)));
    vector<tuple<int, int, int>> score(T + 1);
    for (int i = 0; i < R; i++) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        data[t][p].first = m + data[t][p].second * 20;
        get<0>(score[t])--;
      } else {
        data[t][p].second++;
      }
    }
    for (int i = 1; i <= T; i++) {
      int sco = 0, pena = 0;
      for (int j = 0; j <= P; j++) {
        if (data[i][j].first) {
          sco--;
          pena += data[i][j].first;
        }
      }
      score[i] = tuple<int, int, int>(get<0>(score[i]), pena, -i);
    }
    sort(score.begin() + 1, score.end());
    tuple<int, int, int> temp = score[1];
    cout << -get<2>(score[1]);
    for (int i = 2; i <= T; i++) {
      if (get<0>(temp) == get<0>(score[i]) &&
          get<1>(temp) == get<1>(score[i])) {
        cout << "=";
      } else {
        cout << ",";
      }
      cout << -get<2>(score[i]);
      temp = score[i];
    }
    cout << endl;
  }
  return 0;
}

Error: -6
free(): invalid size


Fixed submission:

#include <algorithm>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int M, T, P, R, m, t, p, j;
  while (cin >> M >> T >> P >> R, M || T || P || R) {
    vector<vector<pair<int, int>>> data(
        T + 1, vector<pair<int, int>>(P, pair<int, int>(0, 0)));
    vector<tuple<int, int, int>> score(T + 1);
    for (int i = 0; i < R; i++) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        data[t][p].first = m + data[t][p].second * 20;
      } else {
        data[t][p].second++;
      }
    }
    for (int i = 1; i <= T; i++) {
      int sco = 0, pena = 0;
      for (int j = 0; j < P; j++) {
        if (data[i][j].first) {
          sco--;
          pena += data[i][j].first;
        }
      }
      score[i] = tuple<int, int, int>(sco, pena, -i);
    }
    sort(score.begin() + 1, score.end());
    tuple<int, int, int> temp = score[1];
    cout << -get<2>(score[1]);
    for (int i = 2; i <= T; i++) {
      if (get<0>(temp) == get<0>(score[i]) &&
          get<1>(temp) == get<1>(score[i])) {
        cout << "=";
      } else {
        cout << ",";
      }
      cout << -get<2>(score[i]);
      temp = score[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00768 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

class team {
public:
  int id, solve, time, miss[11];
  bool operator<(const team &rhs) const {
    if (solve > rhs.solve)
      return true;
    else if (solve == rhs.solve && time < rhs.time)
      return true;
    else if (solve == rhs.solve && time == rhs.time && id > rhs.id)
      return true;
    return false;
  }
};
int main(void) {
  int M, T, P, R;
  int m, t, p, j;
  team teams[51];
  while (cin >> M >> T >> P >> R && M) {
    rep(i, T) {
      teams[i].id = i + 1;
      teams[i].solve = 0;
      teams[i].time = 0;
      rep(j, P + 1) teams[i].miss[j] = 0;
    }
    rep(i, R) {
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        teams[t].solve++;
        teams[t].time += m + teams[t].miss[p] * 20;
      } else {
        teams[t].miss[p]++;
      }
    }
    sort(teams, teams + T);
    rep(i, T - 1) {
      cout << teams[i].id;
      if (teams[i].solve == teams[i + 1].solve &&
          teams[i].time == teams[i + 1].time) {
        cout << "=";
      } else {
        cout << ",";
      }
    }
    cout << teams[T - 1].id << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

class team {
public:
  int id, solve, time, miss[11];
  bool operator<(const team &rhs) const {
    return solve < rhs.solve || (solve == rhs.solve && time > rhs.time) ||
           id < rhs.id;
  }
};
int main(void) {
  int M, T, P, R;
  int m, t, p, j;
  team teams[51];
  while (cin >> M >> T >> P >> R && M) {
    rep(i, T) {
      teams[i].id = i + 1;
      teams[i].solve = 0;
      teams[i].time = 0;
      rep(j, P) teams[i].miss[j] = 0;
    }
    rep(i, R) {
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        teams[t].solve++;
        teams[t].time += m + teams[t].miss[p] * 20;
      } else {
        teams[t].miss[p]++;
      }
    }
    sort(teams, teams + T);
    for (int i = T - 1; i > 0; --i) {
      cout << teams[i].id;
      if (teams[i].solve == teams[i - 1].solve &&
          teams[i].time == teams[i - 1].time) {
        cout << "=";
      } else {
        cout << ",";
      }
    }
    cout << teams[0].id << endl;
  }
}
Problem p00768 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int main() {
  while (true) {
    int m, t, p, r;
    scanf("%d%d%d%d", &m, &t, &p, &r);
    if (m == 0)
      break;
    int tim[50][10] = {}, wa[50][10] = {};
    rep(i, 50) rep(j, 10) tim[i][j] = -1;
    rep(i, r) {
      int mm, tt, pp, jj;
      scanf("%d%d%d%d", &mm, &tt, &pp, &jj);
      tt--, pp--;
      if (jj == 0)
        tim[tt][pp] = mm + wa[tt][pp] * 20;
      else
        wa[tt][pp]++;
    }
    int pen[50] = {}, acp[50] = {};
    rep(i, t) rep(j, p) {
      if (tim[i][j] == -1)
        continue;
      acp[i]++;
      pen[i] += tim[i][j];
    }
    vector<PP> vc;
    rep(i, t) vc.push_back(PP(P(acp[i], -pen[i]), i + 1));
    sort(vc.begin(), vc.end(), greater<PP>());
    rep(i, t) {
      if (i == 0) {
        printf("%d", vc[i].second);
        continue;
      }
      if (vc[i].first == vc[i - 1].first)
        printf("=%d", vc[i].second);
      else
        printf(",%d", vc[i].second);
      //			cout << vc[i].second << " acp " <<
      //vc[i].first.first << " pen " << vc[i].first.second << endl;
    }
    printf("\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int main() {
  while (true) {
    int m, t, p, r;
    scanf("%d%d%d%d", &m, &t, &p, &r);
    if (m == 0)
      break;
    int tim[50][10] = {}, wa[50][10] = {};
    rep(i, 50) rep(j, 10) tim[i][j] = -1;
    rep(i, r) {
      int mm, tt, pp, jj;
      scanf("%d%d%d%d", &mm, &tt, &pp, &jj);
      tt--, pp--;
      if (jj == 0)
        tim[tt][pp] = mm + wa[tt][pp] * 20;
      else
        wa[tt][pp]++;
    }
    int pen[10] = {}, acp[10] = {};
    rep(i, t) rep(j, p) {
      if (tim[i][j] == -1)
        continue;
      acp[i]++;
      pen[i] += tim[i][j];
    }
    vector<PP> vc;
    rep(i, t) vc.push_back(PP(P(acp[i], -pen[i]), i + 1));
    sort(vc.begin(), vc.end(), greater<PP>());
    rep(i, t) {
      if (i == 0) {
        printf("%d", vc[i].second);
        continue;
      }
      if (vc[i].first == vc[i - 1].first)
        printf("=%d", vc[i].second);
      else
        printf(",%d", vc[i].second);
      //			cout << vc[i].second << " acp " <<
      //vc[i].first.first << " pen " << vc[i].first.second << endl;
    }
    printf("\\n");
  }
  return 0;
}
Problem p00768 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

piii mk(int a, int b, int c) { return piii(pii(a, b), c); }

int main() {
A:;

  int teemwrong[55][11] = {0};
  int teemcost[55] = {0};
  int teemac[55] = {0};

  int M, T, P, R;
  cin >> M >> T >> P >> R;

  if (M == 0 && T == 0 && R == 0 && P == 0)
    return 0;

  rep(i, R) {
    int m, t, p, j;
    cin >> m >> t >> p >> j;

    if (j == 0) {
      teemac[t]++;
      teemcost[t] += m + teemwrong[t][p] * 20;
    } else {
      teemwrong[t][p]++;
    }
  }

  vector<piii> rank;
  reps(i, 1, T + 1) { rank.push_back(mk(teemac[i], -teemcost[i], i)); }

  sort(rank.begin(), rank.end());
  reverse(rank.begin(), rank.end());

  rep(i, rank.size()) {
    if (i != 0) {
      if (rank[i].first == rank[i - 1].first)
        printf("=");
      else
        printf(",");
    }
    printf("%d", rank[i].second);
  }
  puts("");

  goto A;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

piii mk(int a, int b, int c) { return piii(pii(a, b), c); }

int main() {
A:;

  int teemwrong[55][11] = {0};
  int teemcost[11] = {0};
  int teemac[11] = {0};

  int M, T, P, R;
  cin >> M >> T >> P >> R;

  if (M == 0 && T == 0 && R == 0 && P == 0)
    return 0;

  rep(i, R) {
    int m, t, p, j;
    cin >> m >> t >> p >> j;

    if (j == 0) {
      teemac[t]++;
      teemcost[t] += m + teemwrong[t][p] * 20;
    } else {
      teemwrong[t][p]++;
    }
  }

  vector<piii> rank;
  reps(i, 1, T + 1) { rank.push_back(mk(teemac[i], -teemcost[i], i)); }

  sort(rank.begin(), rank.end());
  reverse(rank.begin(), rank.end());

  rep(i, rank.size()) {
    if (i != 0) {
      if (rank[i].first == rank[i - 1].first)
        printf("=");
      else
        printf(",");
    }
    printf("%d", rank[i].second);
  }
  puts("");

  goto A;
}
Problem p00768 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int x[100][2], y[100][20], n, a, b, c, d, e, f, g, h, p;
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    cin >> n >> a >> b >> c;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < c; i++) {
      cin >> d >> e >> f >> g;
      if (g != 0) {
        y[e][f] += 20;
      } else {
        x[e][1] += d + y[e][f];
        x[e][0]++;
      }
    }
    p = 0;
    for (int i = b; i >= 0; i--) {
      for (int j = 0; j <= 100000; j++) {
        h = 0;
        for (int k = a; k > 0; k--) {
          if (x[k][0] == i && x[k][1] == j) {
            if (h >= 1) {
              cout << '=';
            } else if (p >= 1) {
              cout << ',';
            }
            cout << k;
            p++;
            h++;
          }
        }
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int x[100][3], n, a, b, c, d, e, f, g, h, p;
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    cin >> n >> a >> b >> c;
    for (int i = 0; i < c; i++) {
      cin >> d >> e >> f >> g;
      if (g) {
        x[e][2] += 20;
      } else {
        x[e][1] = d + x[e][2];
        x[e][0]++;
      }
    }
    p = 0;
    for (int i = 10; i >= 0; i--) {
      for (int j = 0; j <= 1000; j++) {
        h = 0;
        for (int k = a; k > 0; k--) {
          if (x[k][0] == i && x[k][1] == j) {
            if (h >= 1) {
              cout << '=';
            } else if (p >= 1) {
              cout << ',';
            }
            cout << k;
            p++;
            h++;
          }
        }
      }
    }
    cout << endl;
  }
}
Problem p00768 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int M, T, P, R;
    cin >> M >> T >> P >> R;

    if (M == 0 && T == 0 && P == 0 && R == 0)
      return 0;

    int m, t, p, j;
    int result[T];
    fill(result, result + T, 0);
    int time[T];
    fill(time, time + T, 0);
    int failure[T][P];
    fill(failure[0], failure[T] + P, 0);
    for (int submit = 0; submit < R; submit++) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        result[t - 1] += 1;
        time[t - 1] += m + failure[t - 1][p - 1] * 20;
      } else {
        ++failure[t - 1][p - 1];
      }
    }

    bool done[T];
    fill(done, done + T, false);
    int prevPoint, prevTime;
    for (int count = 0; count < T; count++) {
      int maxPoint = -1;
      int maxTeam = 0;
      int minTime = 100000;
      for (int i = T - 1; i >= 0; i--) {
        if (done[i])
          continue;
        if (maxPoint < result[i]) {
          maxPoint = result[i];
          maxTeam = i + 1;
          minTime = time[i];
        } else if (maxPoint == result[i]) {
          if (minTime > time[i]) {
            minTime = time[i];
            maxTeam = i + 1;
          }
        }
      }
      minTime = time[maxTeam - 1];
      if (count != 0) {
        if (maxPoint == prevPoint && minTime == prevTime)
          cout << "=";
        else
          cout << ",";
      }
      cout << maxTeam;
      done[maxTeam - 1] = true;
      prevPoint = maxPoint;
      prevTime = minTime;
    }
    cout << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int M, T, P, R;
    cin >> M >> T >> P >> R;

    int m, t, p, j;
    int result[T];
    fill(result, result + T, 0);
    int time[T];
    fill(time, time + T, 0);
    int failure[T];
    fill(failure, failure + T, 0);
    for (int submit = 0; submit < R; submit++) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        result[t - 1] += 1;
        time[t - 1] += m + failure[t - 1] * 20;
      } else {
        ++failure[t - 1];
      }
    }

    bool done[T];
    fill(done, done + T, false);
    int prevPoint, prevTime;
    for (int count = 0; count < T; count++) {
      int maxPoint = -1;
      int maxTeam = 0;
      int minTime = 100000;
      for (int i = T - 1; i >= 0; i--) {
        if (done[i])
          continue;
        if (maxPoint < result[i]) {
          maxPoint = result[i];
          maxTeam = i + 1;
          minTime = time[i];
        } else if (maxPoint == result[i]) {
          if (minTime > time[i]) {
            minTime = time[i];
            maxTeam = i + 1;
          }
        }
      }
      minTime = time[maxTeam - 1];
      if (count != 0) {
        if (maxPoint == prevPoint && minTime == prevTime)
          cout << "=";
        else
          cout << ",";
      }
      cout << maxTeam;
      done[maxTeam - 1] = true;
      prevPoint = maxPoint;
      prevTime = minTime;
    }
    cout << endl;
  }
  return 0;
}
Problem p00768 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define MP(a, b) make_pair(a, b)
#define F first
#define S second

int main() {
  int M, T, P, R;
  while (cin >> M >> T >> P >> R, M || T || P || R) {
    vector<pair<int, pair<int, int>>> vp;

    int pena[51][11];

    REP(i, 0, T) vp.push_back(MP(0, MP(0, -i - 1)));
    REP(i, 0, 51) REP(j, 0, 11) pena[i][j] = 0;

    REP(i, 0, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      p--;

      if (j == 0) {
        vp[t].F--;
        vp[t].S.F += (pena[t][p] + m);
      } else {
        pena[t][p] += 20;
      }
    }

    sort(vp.begin(), vp.end());

    cout << -vp[0].S.S;
    REP(i, 1, vp.size()) {
      if (vp[i - 1].F < vp[i].F) {
        cout << "," << -vp[i].S.S;
      } else if (vp[i - 1].S.F < vp[i].S.F) {
        cout << "," << -vp[i].S.S;
      } else {
        cout << "=" << -vp[i].S.S;
      }
    }

    cout << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define RREP(i, a, n) for (int i = n - 1; i >= a; i--)
#define INF 1000000000
#define MP(a, b) make_pair(a, b)
#define F first
#define S second

int main() {
  int M, T, P, R;
  while (cin >> M >> T >> P >> R) {
    vector<pair<int, pair<int, int>>> vp; // correct, time, team
    int pena[51][11];

    REP(i, 0, T) vp.push_back(MP(0, MP(0, -i - 1)));
    REP(i, 0, 51) REP(j, 0, 11) pena[i][j] = 0;

    REP(i, 0, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      p--;

      if (j == 0) {
        vp[t].F--;
        vp[t].S.F += (pena[t][p] + m);
      } else {
        pena[t][p] += 20;
      }
    }

    sort(vp.begin(), vp.end());
    // reverse(vp.begin(), vp.end());

    cout << -vp[0].S.S;
    REP(i, 1, vp.size()) {
      if (vp[i - 1].F < vp[i].F) {
        cout << "," << -vp[i].S.S;
      } else if (vp[i - 1].S.F < vp[i].S.F) {
        cout << "," << -vp[i].S.S;
      } else {
        cout << "=" << -vp[i].S.S;
      }
    }

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

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int M, T, P, R;
    cin >> M >> T >> P >> R;

    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;

    int CP[50], TT[50], PT[50][10];
    for (int i = 0; i < T; i++) {
      CP[i] = TT[i] = 0;
      for (int j = 0; j < P; j++)
        PT[i][j] = 0;
    }

    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;

      if (j == 0) {
        CP[t - 1]++;
        TT[t - 1] += (m + PT[t - 1][p - 1]);
      } else {
        PT[t - 1][p - 1] += 20;
      }
    }

    int tnow, tpre = -1;
    bool flg[50];
    for (int i = 0; i < T; i++)
      flg[i] = false;

    for (int i = 0; i < T; i++) {
      tnow = -1;
      for (int j = 0; j < T; j++) {
        if (flg[j])
          continue;

        if (tnow == -1) {
          tnow = j;
        } else {
          if (CP[j] > CP[tnow] || (CP[j] == CP[tnow] && TT[j] <= TT[tnow])) {
            tnow = j;
          }
        }
      }

      if (tpre != -1) {
        if (CP[tnow] == CP[tpre] && TT[tnow] == TT[tpre])
          cout << '=';
        else
          cout << ',';
      }
      cout << tnow + 1;

      flg[tnow] = true;
      tpre = tnow;
    }
    cout << endl;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int M, T, P, R;
    cin >> M >> T >> P >> R;

    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;

    int CP[50], TT[50], PT[50][10];
    for (int i = 0; i < R; i++) {
      CP[i] = TT[i] = 0;
      for (int j = 0; j < P; j++) {
        PT[i][j] = 0;
      }
    }

    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;

      if (j == 0) {
        CP[t - 1]++;
        TT[t - 1] += (m + PT[t - 1][p - 1]);
      } else {
        PT[t - 1][p - 1] += 20;
      }
    }

    int tnow, tpre = -1;
    bool flg[50];
    for (int i = 0; i < T; i++) {
      flg[i] = false;
    }

    for (int i = 0; i < T; i++) {
      tnow = -1;
      for (int j = 0; j < T; j++) {
        if (flg[j])
          continue;

        if (tnow = -1) {
          tnow = j;
        } else {
          if (CP[j] > CP[tnow] || (CP[j] == CP[tnow] && TT[j] <= TT[tnow])) {
            tnow = j;
          }
        }
      }

      if (tpre != -1) {
        if (CP[tnow] == CP[tpre] && TT[tpre] <= TT[tnow]) {
          cout << '=';
        } else {
          cout << '.';
        }
      }
      cout << tnow + 1;

      flg[tnow] = true;
      tpre = tnow;
    }
    cout << endl;
  }

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

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

struct Info {
  int id, cost, ac;
};

bool operator<(const Info &a, const Info &b) {
  if (a.ac != b.ac)
    return a.ac > b.ac;
  if (a.cost != b.cost)
    return a.cost < b.cost;
  return a.id > b.id;
}

int main() {
  int M, T, P, R;
  while (cin >> M >> T >> P >> R) {
    if (M == 0)
      break;
    vector<vector<int>> num_WA(T, vector<int>(P, 0));
    vector<int> cost(T, 0);
    vector<int> num_AC(T, 0);
    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      p--;
      if (j == 0) {
        cost[t] += m + num_WA[t][p] * 20;
        num_AC[t]++;
      } else {
        num_WA[t][p]++;
      }
    }
    vector<Info> temp;
    for (int i = 0; i < T; i++) {
      Info hoge;
      hoge.cost = cost[i];
      hoge.id = i + 1;
      hoge.ac = num_AC[i];
      temp.push_back(hoge);
    }
    sort(temp.begin(), temp.end());
    int bef_ac = 0, bef_cost = 0;
    for (int i = 0; i < temp.size(); i++) {
      if (i != 0) {
        if (bef_ac == temp[i].ac && bef_cost == temp[i].cost) {
          cout << "=";
        } else
          cout << ",";
      }
      cout << temp[i].id;
      bef_ac = temp[i].ac;
      bef_cost = temp[i].cost;
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

struct Info {
  int id, cost, ac;
};

bool operator<(const Info &a, const Info &b) {
  if (a.ac != b.ac)
    return a.ac > b.ac;
  if (a.cost != b.cost)
    return a.cost < b.cost;
  return a.id > b.id;
}

int main() {
  int M, T, P, R;
  while (cin >> M >> T >> P >> R) {
    if (M == 0)
      break;
    vector<vector<int>> num_WA(T, vector<int>(P, 0));
    vector<int> cost(T, 0);
    vector<int> num_AC(T, 0);
    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        cost[t] += m + num_WA[t][p] * 20;
        num_AC[t]++;
      } else {
        num_WA[t][p]++;
      }
    }
    vector<Info> temp;
    for (int i = 0; i < T; i++) {
      Info hoge;
      hoge.cost = cost[i];
      hoge.id = i + 1;
      hoge.ac = num_AC[i];
      temp.push_back(hoge);
    }
    sort(temp.begin(), temp.end());
    int bef_ac = 0, bef_cost = 0;
    for (int i = 0; i < temp.size(); i++) {
      if (i != 0) {
        if (bef_ac == temp[i].ac && bef_cost == temp[i].cost) {
          cout << "=";
        } else
          cout << ",";
      }
      cout << temp[i].id;
      bef_ac = temp[i].ac;
      bef_cost = temp[i].cost;
    }
    cout << endl;
  }
  return 0;
}