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

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x, min, max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int, int> PII;

const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};

int M, T, P, R;

struct Score {
  Score() {
    count = 0;
    time = 0;
  }
  int team;
  int count;
  int time;

  bool operator<(const Score &right) const {
    if (count != right.count) {
      return count > right.count;
    }
    if (time != right.time) {
      return time < right.time;
    }
    return team > right.team;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;
    vector<Score> score(T);
    VII pena(T, VI(P, 0));
    rep(i, T) { score[i].team = i; }
    rep(i, R) {
      int m, t, p, f;
      cin >> m >> t >> p >> f;
      if (f != 0) {
        pena[t - 1][p - 1] += 20;
      } else {
        score[t - 1].count++;
        score[t - 1].time += m + pena[t - 1][p - 1];
      }
    }
    sort(all(score));
    rep(i, score.size()) {
      if (i != 0) {
        cout << (score[i - 1].count == score[i].count &&
                         score[i - 1].time == score[i].time
                     ? '='
                     : ',');
      }
      cout << score[i].team + 1;
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x, min, max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int, int> PII;

const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};

int M, T, P, R;

struct Score {
  Score() {
    count = 0;
    time = 0;
  }
  int team;
  int count;
  int time;

  bool operator<(const Score &right) const {
    if (count != right.count) {
      return count > right.count;
    }
    if (time != right.time) {
      return time < right.time;
    }
    return team > right.team;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;
    vector<Score> score(T);
    VII pena(T, VI(P, 0));
    rep(i, T) { score[i].team = i; }
    rep(i, R) {
      int m, t, p, f;
      cin >> m >> t >> p >> f;
      if (f != 0) {
        pena[t - 1][p] += 20;
      } else {
        score[t - 1].count++;
        score[t - 1].time += m + pena[t - 1][p];
      }
    }
    sort(all(score));
    rep(i, score.size()) {
      if (i != 0) {
        cout << (score[i - 1].count == score[i].count &&
                         score[i - 1].time == score[i].time
                     ? '='
                     : ',');
      }
      cout << score[i].team + 1;
    }
    cout << endl;
  }
  return 0;
}