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

#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v;
vector<vector<int>> miss;
vector<vector<int>> score;
vector<vector<pair<int, int>>> rk;

void solve(int m, int t, int p, int r) {
  int in;
  v = vector<vector<int>>(r, vector<int>(4, 0));
  miss = vector<vector<int>>(t, vector<int>(p, 0));
  score = vector<vector<int>>(t, vector<int>(2, 0));
  rk = vector<vector<pair<int, int>>>(p + 1, vector<pair<int, int>>(0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> in;
      v[i][j] = in;
    }
  }
  for (int i = 0; i < r; i++) {
    if (v[i][3])
      miss[v[i][1] - 1][v[i][2] - 1]++;
    else {
      score[v[i][1] - 1][0]++;
      score[v[i][1] - 1][1] += v[i][0] + miss[v[i][1] - 1][v[i][2] - 1] * 20;
    }
  }
  for (int i = t - 1; i >= 0; i--) {
    rk[score[i][0]].push_back(make_pair(i, score[i][1]));
  }
  bool sw = false;
  for (int i = p; i >= 0; i--) {
    int maxx = -1;
    for (int j = 0; j < rk[i].size(); j++) {
      maxx = max(maxx, rk[i][j].second);
    }
    for (int j = 0; j <= maxx; j++) {
      bool swc = false;
      for (int k = 0; k < rk[i].size(); k++) {
        if (rk[i][k].second == j) {
          if (swc)
            cout << "=" << rk[i][k].first + 1;
          else {
            if (sw)
              cout << "," << rk[i][k].first + 1;
            else {
              cout << rk[i][k].first + 1;
            }
            sw = true;
          }
          swc = true;
        }
      }
    }
  }
  cout << endl;
}

int main(void) {
  ios::sync_with_stdio(false);
  int a, b, c, d;
  while (cin >> a >> b >> c >> d, a) {
    solve(a, b, c, d);
  }
}

Error: WA

Fixed submission:

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

void solve(int m, int t, int p, int r) {
  int in;
  vector<vector<int>> v;
  v = vector<vector<int>>(r, vector<int>(4, 0));
  vector<vector<int>> miss;
  miss = vector<vector<int>>(t, vector<int>(p, 0));
  vector<vector<int>> score;
  score = vector<vector<int>>(t, vector<int>(2, 0));
  vector<vector<pair<int, int>>> rk;
  rk = vector<vector<pair<int, int>>>(4, vector<pair<int, int>>(0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> in;
      v[i][j] = in;
    }
  }
  for (int i = 0; i < r; i++) {
    if (v[i][3])
      miss[v[i][1] - 1][v[i][2] - 1]++;
    else {
      score[v[i][1] - 1][0]++;
      score[v[i][1] - 1][1] = v[i][0] + miss[v[i][1] - 1][v[i][2] - 1] * 20;
    }
  }
  for (int i = t - 1; i >= 0; i--) {
    rk[score[i][0]].push_back(make_pair(i, score[i][1]));
    // cout<<score[i][1]<<" ";
  }
  for (int i = 3; i >= 0; i--) {
    int maxx = -1;
    for (int j = 0; j < rk[i].size(); j++) {
      maxx = max(maxx, rk[i][j].second);
    }
    bool sw = false;
    for (int j = 0; j <= maxx; j++) {
      bool swc = false;
      for (int k = 0; k < rk[i].size(); k++) {
        if (rk[i][k].second == j) {
          if (swc)
            cout << "=" << rk[i][k].first + 1;
          else {
            if (sw)
              cout << "," << rk[i][k].first + 1;
            else {
              cout << rk[i][k].first + 1;
              sw = true;
            }
          }
          swc = true;
        }
      }
    }
    if (i && sw)
      cout << ",";
  }
  cout << endl;
}

int main(void) {
  int a, b, c, d;
  while (cin >> a >> b >> c >> d, a) {
    solve(a, b, c, d);
  }
}