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

#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

// #define LOCAL 0
// #ifdef LOCAL
// #define DEBUG(s) cout << (s) << endl
// #define dump(x)  cerr << #x << " = " << (x) << endl
// #define BR cout << endl;
// #else
// #define DEBUG(s) do{}while(0)
// #define dump(x) do{}while(0)
// #define BR
// #endif

// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 // デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
// ここから編集する

void solve(int n, int w, int d) {
  vector<pair<int, int>> vp;
  vp.emplace_back(w, d);
  rep(i, 0, n) {
    int cnt = i;
    int p, s;
    cin >> s >> p;
    s--;
    //        s += i;
    int sw = vp[s].first;
    int sd = vp[s].second;
    p %= 2 * (sw + sd);
    //        remove(vp.begin()+s,vp.begin()+s+1);
    vp.erase(vp.begin() + s);
    if (p < sw) {
      pair<int, int> cut1{sw - p, sd};
      pair<int, int> cut2{p, sd};
      if (sw - p > p) {
        vp.push_back(cut2);
        vp.push_back(cut1);
      } else {
        vp.push_back(cut1);
        vp.push_back(cut2);
      }
      continue;
    }
    p -= sw;
    if (p < sd) {
      pair<int, int> cut1{sw, sd - p};
      pair<int, int> cut2{sw, p};
      if (sd - p > p) {
        vp.push_back(cut2);
        vp.push_back(cut1);
      } else {
        vp.push_back(cut1);
        vp.push_back(cut2);
      }
      continue;
    }
    p -= sd;
    if (p < sw) {
      pair<int, int> cut1{sw - p, sd};
      pair<int, int> cut2{p, sd};
      if (sw - p > p) {
        vp.push_back(cut2);
        vp.push_back(cut1);
      } else {
        vp.push_back(cut1);
        vp.push_back(cut2);
      }
      continue;
    }
    p -= sw;
    if (p < sd) {
      pair<int, int> cut1{sw, sd - p};
      pair<int, int> cut2{sw, p};
      if (sd - p > p) {
        vp.push_back(cut2);
        vp.push_back(cut1);
      } else {
        vp.push_back(cut1);
        vp.push_back(cut2);
      }
      continue;
    }
  }
  vector<int> v;

  rep(i, 0, vp.size()) { v.push_back(vp[i].first * vp[i].second); }
  sort(all(v));
  rep(i, 0, vp.size()) {
    cout << v[i];
    if (i == vp.size() - 1)
      cout << endl;
    else
      cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    int n, w, d;
    cin >> n >> w >> d;
    if (w == 0)
      break;
    solve(n, w, d);
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

// #define LOCAL 0
// #ifdef LOCAL
// #define DEBUG(s) cout << (s) << endl
// #define dump(x)  cerr << #x << " = " << (x) << endl
// #define BR cout << endl;
// #else
// #define DEBUG(s) do{}while(0)
// #define dump(x) do{}while(0)
// #define BR
// #endif

// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 // デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
// ここから編集する

void solve(int n, int w, int d) {
  vector<pair<int, int>> vp;
  vp.emplace_back(w, d);
  rep(i, 0, n) {
    int p, s;
    cin >> s >> p;
    s--;
    int sw = vp[s].first;
    int sd = vp[s].second;
    p %= 2 * (sw + sd);
    if (p < sw) {
      pair<int, int> cut1{sw - p, sd};
      pair<int, int> cut2{p, sd};
      if (sw - p > p) {
        vp[s] = cut2;
        vp.push_back(cut1);
      } else {
        vp[s] = cut1;
        vp.push_back(cut2);
      }
      continue;
    }
    p -= sw;
    if (p < sd) {
      pair<int, int> cut1{sw, sd - p};
      pair<int, int> cut2{sw, p};
      if (sd - p > p) {
        vp[s] = cut2;
        vp.push_back(cut1);
      } else {
        vp[s] = cut1;
        vp.push_back(cut2);
      }
      continue;
    }
    p -= sd;
    if (p < sw) {
      pair<int, int> cut1{sw - p, sd};
      pair<int, int> cut2{p, sd};
      if (sw - p > p) {
        vp[s] = cut2;
        vp.push_back(cut1);
      } else {
        vp[s] = cut1;
        vp.push_back(cut2);
      }
      continue;
    }
    p -= sw;
    if (p < sd) {
      pair<int, int> cut1{sw, sd - p};
      pair<int, int> cut2{sw, p};
      if (sd - p > p) {
        vp[s] = cut2;
        vp.push_back(cut1);
      } else {
        vp[s] = cut1;
        vp.push_back(cut2);
      }
      continue;
    }
  }
  vector<int> v;

  rep(i, 0, vp.size()) { v.push_back(vp[i].first * vp[i].second); }
  sort(all(v));
  rep(i, 0, vp.size()) {
    cout << v[i];
    if (i == vp.size() - 1)
      cout << endl;
    else
      cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    int n, w, d;
    cin >> n >> w >> d;
    if (w == 0)
      break;
    solve(n, w, d);
  }

  return 0;
}