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

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a, c) memset(a, c, sizeof(a))

#define DEBUG(x)                                                               \\
  cout << "#x"                                                                 \\
       << ": " << x << endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX / 3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

map<int, bool> used;
map<int, int> count_t;
map<int, bool> isDecided;

int main() {
  while (true) {
    int n;
    vector<pair<pair<int, int>, pair<int, int>>> t;
    cin >> n;
    if (n == 0)
      break;
    used.clear();
    count_t.clear();
    isDecided.clear();
    REP(i, n) {
      int I, A, U, P;
      cin >> I >> U >> A >> P;
      t.PB(MP(MP(-A, P), MP(I, U)));
      used[I] = false;
      count_t[U] = false;
      isDecided[I] = false;
    }
    sort(ALL(t));
    // 	REP(i,n) printf("A: %d P: %d I: %d U:
    // %d\\n",-t[i].first.first,t[i].first.second,t[i].second.first,t[i].second.second);
    int temp = 0;
    //
    // 	REP(i,n){
    // 	    if(!used[t[i].second.second]){
    // 		used[t[i].second.second] = true;
    // 		count_t[t[i].second.second]++;
    // 		isDecided[t[i].second.first] = true;
    // 		temp++;
    // 	    }
    // 	}

    if (temp < 10) {
      REP(i, n) {
        if (!isDecided[t[i].second.first] && count_t[t[i].second.second] < 3) {
          count_t[t[i].second.second]++;
          isDecided[t[i].second.first] = true;
          temp++;
        }
        if (temp == 10)
          break;
      }
    }

    if (temp < 20) {
      REP(i, n) {
        if (!isDecided[t[i].second.first] && count_t[t[i].second.second] < 2) {
          count_t[t[i].second.second]++;
          isDecided[t[i].second.first] = true;
          temp++;
        }
        if (temp == 20)
          break;
      }
    }

    if (temp < 26) {
      REP(i, n) {
        if (!isDecided[t[i].second.first] && count_t[t[i].second.second] < 1) {
          count_t[t[i].second.second]++;
          isDecided[t[i].second.first] = true;
          temp++;
        }
        if (temp == 26)
          break;
      }
    }

    REP(i, n) {
      if (isDecided[t[i].second.first])
        cout << t[i].second.first << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a, c) memset(a, c, sizeof(a))

#define DEBUG(x)                                                               \\
  cout << "#x"                                                                 \\
       << ": " << x << endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX / 3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector<bool> used;
vector<int> count_t;
vector<bool> isDecided;
vector<int> ans;

int main() {
  while (true) {
    int n;
    vector<pair<pair<int, int>, pair<int, int>>> t;
    cin >> n;
    if (n == 0)
      break;
    REP(i, n) {
      int I, A, U, P;
      cin >> I >> U >> A >> P;
      t.PB(MP(MP(-A, P), MP(I, U)));
      sort(ALL(t));
    }
    used = vector<bool>(n * 2, false);
    count_t = vector<int>(n * 2, 0);
    isDecided = vector<bool>(n * 2, false);
    ans = vector<int>();

    REP(i, n) {
      if (!used[t[i].second.second - 1]) {
        used[t[i].second.second - 1] = true;
        count_t[t[i].second.second - 1]++;
        isDecided[t[i].second.first - 1] = true;
        ans.PB(t[i].second.first);
      }
    }

    if (ans.size() < 10) {
      REP(i, n) {
        if (!isDecided[t[i].second.first - 1] &&
            count_t[t[i].second.second - 1] < 3) {
          count_t[t[i].second.second - 1]++;
          isDecided[t[i].second.second - 1] = true;
          ans.PB(t[i].second.first);
        }
      }
    }

    if (ans.size() < 20) {
      REP(i, n) {
        if (!isDecided[t[i].second.first - 1] &&
            count_t[t[i].second.second - 1] < 2) {
          count_t[t[i].second.second - 1]++;
          isDecided[t[i].second.first - 1] = true;
          ans.PB(t[i].second.first);
        }
      }
    }

    if (ans.size() < 26) {
      REP(i, n) {
        if (!isDecided[t[i].second.second - 1] &&
            count_t[t[i].second.second - 1] < 1) {
          count_t[t[i].second.second - 1]++;
          isDecided[t[i].second.first - 1] = true;
          ans.PB(t[i].second.first);
        }
      }
    }

    sort(ALL(ans));
    REP(i, ans.size()) cout << ans[i] << endl;
  }

  return 0;
}