Problem p00768 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

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

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define INF 1 << 30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> pii;

typedef long long ll;

class team {
public:
  int id;
  int clear;
  vi fail;
  int time;
  team() {
    // id=0;
    // clear=0;
    // fail = vi(10,0);
    // time=0;
  }
};

int main() {
  while (1) {
    int M, T, P, R;
    int m, t, p, j;
    vector<team> tev;
    vector<pii> ap;
    cin >> M >> T >> P >> R;
    if (M == 0)
      break;
    rep(i, T) {
      team te;
      te.id = i + 1;
      te.clear = 0;
      te.time = 0;
      rep(j, 10) { te.fail.pb(0); }
      tev.pb(te);
      //????????§id??????????????°??????????????????clear,time???0??§?????????
    }
    rep(i, R) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        int time = m;
        //????????§?????£?§£??°????????????????????????????????£?§£??°??¨????????????????????????
        time += tev[t - 1].fail[p - 1] * 20;
        tev[t - 1].clear++;
        tev[t - 1].time += time;
      } else {
        //????????§???????????????????????¨????????£?§£?????°?????????
        tev[t - 1].fail[p - 1]++;
      }
    }
    rep(i, T) {
      ap.pb(mp(tev[i].clear * 100000 + (90000 - tev[i].time), tev[i].id));
    }
    sort(rall(ap));

    cout << ap[0].se;
    REP(i, 1, T) {
      if (ap[i - 1].fi == ap[i].fi)
        cout << "=";
      else
        cout << ",";
      cout << ap[i].se;
    }
    cout << endl;
    // rep(i,T){
    // 	cout<<"debug clear:"<<tev[i].clear<<" time:"<<tev[i].time;
    // 	cout<<endl;
    // 	rep(j,P){
    // 		cout<<" fail:"<<tev[i].fail[j];
    // 	}
    // 	cout<<endl;
    // }
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

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

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define INF 1 << 30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> pii;

typedef long long ll;

class team {
public:
  int id;
  int clear;
  vi fail;
  int time;
  team() {
    // id=0;
    // clear=0;
    // fail = vi(10,0);
    // time=0;
  }
};

int main() {
  while (1) {
    int M, T, P, R;
    int m, t, p, j;
    vector<team> tev;
    vector<pii> ap;
    cin >> M >> T >> P >> R;
    if (M == 0)
      break;
    rep(i, T) {
      team te;
      te.id = i + 1;
      te.clear = 0;
      te.time = 0;
      te.fail = vi(10, 0);
      tev.pb(te);
      //????????§id??????????????°??????????????????clear,time???0??§?????????
    }
    rep(i, R) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        int time = m;
        //????????§?????£?§£??°????????????????????????????????£?§£??°??¨????????????????????????
        time += tev[t - 1].fail[p] * 20;
        tev[t - 1].clear++;
        tev[t - 1].time += time;
      } else {
        //????????§???????????????????????¨????????£?§£?????°?????????
        tev[t - 1].fail[p]++;
      }
    }
    rep(i, T) {
      ap.pb(mp(tev[i].clear * 100000 + (90000 - tev[i].time), tev[i].id));
    }
    sort(rall(ap));

    cout << ap[0].se;
    REP(i, 1, T) {
      if (ap[i - 1].fi == ap[i].fi)
        cout << "=";
      else
        cout << ",";
      cout << ap[i].se;
    }
    cout << endl;
    // rep(i,T){
    // 	cout<<"debug clear:"<<tev[i].clear<<" time:"<<tev[i].time;
    // 	cout<<endl;
    // 	rep(j,P){
    // 		cout<<" fail:"<<tev[i].fail[j];
    // 	}
    // 	cout<<endl;
    // }
  }
  return 0;
}