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

#include <algorithm>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef tuple<int, int, int, int> RECORD;

class Team {
public:
  int _id;
  int _time;
  int _solveNum;
  vector<int> _probs;

  void init(int i, int M, int P, int R) {
    _id = i;
    _time = 0;
    _solveNum = 0;
    _probs.resize(P + 1, 0);
  }

  void in(int time, int probNum, int b) {
    if (!b) {
      _time += _probs[probNum] * 20 + time;
      _solveNum++;
    } else {
      ++_probs[probNum];
    }
  }

  void dump() const {
    cout << "id=" << _id;
    cout << "time=" << _time;
    cout << "solvenum=" << _solveNum;
  }

  bool operator==(const Team &r) {
    if (this->_solveNum == r._solveNum && this->_time == r._time) {
      //			this->dump();
      //			r.dump();
      return true;
    }
    return false;
  }
};

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

    cin >> M >> T >> P >> R;
    if (M + T + P + R == 0)
      break;
    //		if ( R <= 0)
    //			continue;

    vector<Team> teams(T);
    for (int i = 0; i < T; ++i) {
      teams[i].init(i + 1, M, P, R);
    }

    for (int i = 0; i < R; ++i) {
      int time, teamNum, probNum, ret;
      cin >> time >> teamNum >> probNum >> ret;
      teams[teamNum - 1].in(time, probNum, ret);
    }

    sort(teams.begin(), teams.end(), [](Team t1, Team t2) -> bool {
      int a = t1._solveNum - t2._solveNum;

      if (a > 0)
        return true;

      if (a < 0)
        return false;

      if (t1._time < t2._time)
        return true;

      if (t1._time > t2._time)
        return false;

      if (t1._id > t2._id)
        return true;

      return false;
    });

    auto it = teams.begin();
    cout << (*it)._id;
    for (it += 1; it != teams.end(); ++it) {
      if (*(it - 1) == *(it))
        cout << "=";
      else
        cout << ",";
      cout << (*it)._id;
    }
    cout << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef tuple<int, int, int, int> RECORD;

class Team {
public:
  int _id;
  int _time;
  int _solveNum;
  vector<int> _probs;

  void init(int i, int M, int P, int R) {
    _id = i;
    _time = 0;
    _solveNum = 0;
    _probs.resize(P, 0);
  }

  void in(int time, int probNum, int b) {
    if (!b) {
      _time += _probs[probNum] * 20 + time;
      _solveNum++;
    } else {
      ++_probs[probNum];
    }
  }

  void dump() const {
    cout << "id=" << _id;
    cout << "time=" << _time;
    cout << "solvenum=" << _solveNum;
  }

  bool operator==(const Team &r) {
    if (this->_solveNum == r._solveNum && this->_time == r._time) {
      //			this->dump();
      //			r.dump();
      return true;
    }
    return false;
  }
};

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

    cin >> M >> T >> P >> R;
    if (M + T + P + R == 0)
      break;
    //		if ( R <= 0)
    //			continue;

    vector<Team> teams(T);
    for (int i = 0; i < T; ++i) {
      teams[i].init(i + 1, M, P, R);
    }

    for (int i = 0; i < R; ++i) {
      int time, teamNum, probNum, ret;
      cin >> time >> teamNum >> probNum >> ret;
      teams[teamNum - 1].in(time, probNum, ret);
    }

    stable_sort(teams.begin(), teams.end(), [](Team t1, Team t2) -> bool {
      int a = t1._solveNum - t2._solveNum;

      if (a > 0)
        return true;
      if (a < 0)
        return false;

      if (t1._time < t2._time)
        return true;

      if (t1._id > t2._id)
        return true;

      return false;
    });

    auto it = teams.begin();
    cout << (*it)._id;
    for (it += 1; it != teams.end(); ++it) {
      if (*(it - 1) == *(it))
        cout << "=";
      else
        cout << ",";
      cout << (*it)._id;
    }
    cout << endl;
  }
}