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

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

int main(void) {
  // Your code here!
  while (true) {
    int n, d = 1, u = 1, m = 0, t = 0, a, b;
    cin >> n;
    if (n == 0)
      break;
    vector<int> id(n), s(n), dd(100000);
    for (int i = 0; i < 100000; i++) {
      dd.at(i) = 1;
    }
    for (int i = 0; i < n; i++) {
      cin >> id.at(i);
      t = 0;
      u = 1;
      m = 0;
      d += 3;
      while (true) {
        if (u < 10) {
          cin >> a;
          t = t + a;
          if (m == 0 && t < 10) {
            m++;
            d++;
            continue;
          } else if (t < 10) {
            s.at(i) += (t - a) * dd.at(d - 1);
            s.at(i) += a * dd.at(d);
            d++;
            t = 0;
            u++;
            m = 0;
          } else if (m == 0 && t == 10) {
            s.at(i) += t * dd.at(d);
            dd.at(d + 1)++;
            dd.at(d + 2)++;
            t = 0;
            u++;
            m = 0;
            d++;
          } else {
            s.at(i) += (t - a) * dd.at(d - 1);
            s.at(i) += a * dd.at(d);
            dd.at(d + 1)++;
            t = 0;
            u++;
            m = 0;
            d++;
          }
        }
        if (u == 10) {
          cin >> a >> b;
          if (a + b >= 10) {
            s.at(i) += a * dd.at(d);
            s.at(i) += b * dd.at(d + 1);
            cin >> a;
            s.at(i) += a;
          } else {
            s.at(i) += a * dd.at(d);
            s.at(i) += b * dd.at(d + 1);
          }
          break;
        }
      }
    }
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
      v.at(i).second = s.at(i);
      v.at(i).first = id.at(i);
    }
    sort(v.begin(), v.end(),
         [&](const pair<int, int> &x, const pair<int, int> &y) {
           if (x.second == y.second) {
             return x.first < y.first;
           }
           return x.second > y.second;
         });
    for (int i = 0; i < n; i++) {
      cout << v[i].first << " " << v[i].second << endl;
    }
  }
}


Error: 0

Fixed submission:

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

int main(void) {
  // Your code here!
  while (true) {
    int n, d = 1, u = 1, m = 0, t = 0, a, b;
    cin >> n;
    if (n == 0)
      break;
    vector<int> id(n), s(n), dd(100);
    for (int i = 0; i < 100; i++) {
      dd.at(i) = 1;
    }
    for (int i = 0; i < n; i++) {
      cin >> id.at(i);
      t = 0;
      u = 1;
      m = 0;
      d += 2;
      while (true) {
        if (u < 10) {
          cin >> a;
          t = t + a;
          if (m == 0 && t < 10) {
            m++;
            d++;
            continue;
          } else if (t < 10) {
            s.at(i) += (t - a) * dd.at(d - 1);
            s.at(i) += a * dd.at(d);
            d++;
            t = 0;
            u++;
            m = 0;
          } else if (m == 0 && t == 10) {
            s.at(i) += t * dd.at(d);
            dd.at(d + 1)++;
            dd.at(d + 2)++;
            t = 0;
            u++;
            m = 0;
            d++;
          } else {
            s.at(i) += (t - a) * dd.at(d - 1);
            s.at(i) += a * dd.at(d);
            dd.at(d + 1)++;
            t = 0;
            u++;
            m = 0;
            d++;
          }
        }
        if (u == 10) {
          cin >> a >> b;
          if (a + b >= 10) {
            s.at(i) += a * dd.at(d);
            s.at(i) += b * dd.at(d + 1);
            cin >> a;
            s.at(i) += a;
          } else {
            s.at(i) += a * dd.at(d);
            s.at(i) += b * dd.at(d);
          }
          break;
        }
      }
    }
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
      v.at(i).second = s.at(i);
      v.at(i).first = id.at(i);
    }
    sort(v.begin(), v.end(),
         [&](const pair<int, int> &x, const pair<int, int> &y) {
           if (x.second == y.second) {
             return x.first < y.first;
           }
           return x.second > y.second;
         });
    for (int i = 0; i < n; i++) {
      cout << v[i].first << " " << v[i].second << endl;
    }
  }
}