Problem p00768 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

class Team {
public:
  int id;
  int solvednum;
  int penalty;
  vector<bool> solved;
  vector<int> WA;
  Team(int id, int N) {
    this->id = id;
    solvednum = 0;
    penalty = 0;
    solved.resize(N, false);
    WA.resize(N, 0);
  }
  bool operator==(const Team &t) const { return id == t.id; }
  bool operator<(const Team &t) const {
    if (solvednum == t.solvednum) {
      if (penalty == t.penalty) {
        return id > t.id;
      }
      return penalty < t.penalty;
    }
    return solvednum > t.solvednum;
  }
  string toString() {
    return to_string(id) + " " + to_string(solvednum) + " " +
           to_string(penalty);
  }
};

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int M, T, P, R;
  while (cin >> M >> T >> P >> R, M | T | P | R) {
    vector<Team> teams;
    for (int i = 0; i < T; i++) {
      teams.push_back(Team(i + 1, P));
    }
    for (int asd = 0; asd < R; asd++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        teams[t].solved[p] = true;
        teams[t].solvednum++;
        teams[t].penalty += m + 20 * teams[t].WA[p];
      } else {
        teams[t].WA[p]++;
      }
    }
    sort(teams.begin(), teams.end());

    cout << teams[0].id;
    for (int i = 1; i < T; i++) {
      if (teams[i].solvednum == teams[i - 1].solvednum &&
          teams[i].penalty == teams[i - 1].penalty) {
        cout << '=';
      } else {
        cout << ',';
      }
      cout << teams[i].id;
    }
    cout << endl;
  }
  return 0;
}

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

class Team {
public:
  int id;
  int solvednum;
  int penalty;
  vector<bool> solved;
  vector<int> WA;
  Team(int id, int N) {
    this->id = id;
    solvednum = 0;
    penalty = 0;
    solved.resize(N, false);
    WA.resize(N, 0);
  }
  bool operator==(const Team &t) const { return id == t.id; }
  bool operator<(const Team &t) const {
    if (solvednum == t.solvednum) {
      if (penalty == t.penalty) {
        return id > t.id;
      }
      return penalty < t.penalty;
    }
    return solvednum > t.solvednum;
  }
  string toString() {
    return to_string(id) + " " + to_string(solvednum) + " " +
           to_string(penalty);
  }
};

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int M, T, P, R;
  while (cin >> M >> T >> P >> R, M | T | P | R) {
    vector<Team> teams;
    for (int i = 0; i < T; i++) {
      teams.push_back(Team(i + 1, P + 1));
    }
    for (int asd = 0; asd < R; asd++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        teams[t].solved[p] = true;
        teams[t].solvednum++;
        teams[t].penalty += m + 20 * teams[t].WA[p];
      } else {
        teams[t].WA[p]++;
      }
    }
    sort(teams.begin(), teams.end());

    cout << teams[0].id;
    for (int i = 1; i < T; i++) {
      if (teams[i].solvednum == teams[i - 1].solvednum &&
          teams[i].penalty == teams[i - 1].penalty) {
        cout << '=';
      } else {
        cout << ',';
      }
      cout << teams[i].id;
    }
    cout << endl;
  }
  return 0;
}