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

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

// #define int long long
#define DBG 0
#define dump(o)                                                                \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << " ";                                           \\
  }
#define dumpl(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << endl;                                          \\
  }
#define dumpc(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

class Rectangle {
public:
  int w, d;
  Rectangle(int w, int d) : w(w), d(d){};
  bool operator<(const Rectangle &R) {
    return area() == R.area() ? w < R.w : area() < R.area();
  }
  bool operator==(const Rectangle &R) { return area() == R.area(); }
  int area() const { return w * d; }
};
pair<Rectangle, Rectangle> cut(const Rectangle &R, int s) {
  dump(R.w) dumpl(R.d);
  int ss = s % (R.w + R.d);
  dumpl(ss);
  if (R.w > ss) {
    return make_pair(Rectangle(R.w - ss, R.d), Rectangle(ss, R.d));
  } else {
    ss -= R.w;
    return make_pair(Rectangle(R.w, R.d - ss), Rectangle(R.w, ss));
  }
}

signed main() {
  for (int n, w, d; cin >> n >> w >> d && (n || w || d);) {
    vector<Rectangle> v = {Rectangle(w, d)};
    rep(i, 0, n) {
      dumpl(i);
      dumpl(v.size());
      int p, s;
      cin >> p >> s;
      p--;
      dump(p) dumpl(s);
      auto res = cut(v[p], s);
      Rectangle R1 = res.first, R2 = res.second;
      if (R2 < R1)
        swap(R1, R2);
      v.erase(v.begin() + p);
      v.emplace_back(R1);
      v.emplace_back(R2);
    }
    sort(all(v));
    cout << v[0].area();
    rep(i, 1, v.size()) { cout << " " << v[i].area(); }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

// #define int long long
#define DBG 0
#define dump(o)                                                                \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << " ";                                           \\
  }
#define dumpl(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << endl;                                          \\
  }
#define dumpc(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

class Rectangle {
public:
  int w, d;
  Rectangle(int w, int d) : w(w), d(d){};
  bool operator<(const Rectangle &R) { return area() < R.area(); }
  int area() const { return w * d; }
};
pair<Rectangle, Rectangle> cut(const Rectangle &R, int s) {
  int ss = s % (R.w + R.d);
  if (R.w > ss) {
    return make_pair(Rectangle(R.w - ss, R.d), Rectangle(ss, R.d));
  } else {
    ss -= R.w;
    return make_pair(Rectangle(R.w, R.d - ss), Rectangle(R.w, ss));
  }
}

signed main() {
  for (int n, w, d; cin >> n >> w >> d && (n || w || d);) {
    vector<Rectangle> v = {Rectangle(w, d)};
    rep(i, 0, n) {
      int p, s;
      cin >> p >> s;
      p--;
      auto res = cut(v[p], s);
      Rectangle R1 = res.first, R2 = res.second;
      if (R2 < R1)
        swap(R1, R2);
      v[p] = R1;
      v.emplace_back(R2);
    }
    sort(all(v));
    cout << v[0].area();
    rep(i, 1, v.size()) { cout << " " << v[i].area(); }
    cout << endl;
  }
  return 0;
}