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

#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; i--)
#define chmin(a, b) (a) = min((a), (b));
#define chmax(a, b) (a) = max((a), (b));
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define printV(v)                                                              \\
  cerr << (#v) << ":";                                                         \\
  for (auto(x) : (v)) {                                                        \\
    cerr << " " << (x);                                                        \\
  }                                                                            \\
  cerr << endl;
#define printVS(vs)                                                            \\
  cerr << (#vs) << ":" << endl;                                                \\
  for (auto(s) : (vs)) {                                                       \\
    cerr << (s) << endl;                                                       \\
  }
#define printVV(vv)                                                            \\
  cerr << (#vv) << ":" << endl;                                                \\
  for (auto(v) : (vv)) {                                                       \\
    for (auto(x) : (v)) {                                                      \\
      cerr << " " << (x);                                                      \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#define printP(p) cerr << (#p) << (p).first << " " << (p).second << endl;
#define printVP(vp)                                                            \\
  cerr << (#vp) << ":" << endl;                                                \\
  for (auto(p) : (vp)) {                                                       \\
    cerr << (p).first << " " << (p).second << endl;                            \\
  }

inline void output() { cerr << endl; }
template <typename First, typename... Rest>
inline void output(const First &first, const Rest &...rest) {
  cerr << first << " ";
  output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

struct Cake {
  int t;
  int h, w;
  Cake() {}
  Cake(int _t, int _h, int _w) : t(_t), h(_h), w(_w) {}
  bool operator<(const Cake &o) const {
    if (t != o.t)
      return t < o.t;
    return h * w < o.h * o.w;
  }
};

int n, h, w;
vector<Cake> vec;
int p, s;

void cut(int t) {
  Cake c = vec[p];
  vec.erase(vec.begin() + p);
  Cake c1 = c, c2 = c;
  c1.t = t;
  c2.t = t;
  s %= (c.h + c.w);
  if (s < c.w) {
    c1.w = s;
    c2.w = c.w - s;
  } else {
    s -= c.w;
    c1.h = s;
    c2.h = c.h - s;
  }
  vec.emplace_back(c1);
  vec.emplace_back(c2);
  sort(all(vec));
}

void solve() {
  vec.clear();
  vec.emplace_back(Cake(0, h, w));
  rep(i, n) {
    cin >> p >> s;
    p--;
    cut(i);
  }
  vi ans;
  for (auto c : vec) {
    ans.emplace_back(c.h * c.w);
  }
  sort(all(ans));
  rep(i, ans.size()) { cout << (i ? " " : "") << ans[i]; }
  cout << endl;
}

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

  while (cin >> n >> w >> h, h) {
    solve();
  }
}

Error: 0
hey!
hey!
hey!


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; i--)
#define chmin(a, b) (a) = min((a), (b));
#define chmax(a, b) (a) = max((a), (b));
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define printV(v)                                                              \\
  cerr << (#v) << ":";                                                         \\
  for (auto(x) : (v)) {                                                        \\
    cerr << " " << (x);                                                        \\
  }                                                                            \\
  cerr << endl;
#define printVS(vs)                                                            \\
  cerr << (#vs) << ":" << endl;                                                \\
  for (auto(s) : (vs)) {                                                       \\
    cerr << (s) << endl;                                                       \\
  }
#define printVV(vv)                                                            \\
  cerr << (#vv) << ":" << endl;                                                \\
  for (auto(v) : (vv)) {                                                       \\
    for (auto(x) : (v)) {                                                      \\
      cerr << " " << (x);                                                      \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#define printP(p) cerr << (#p) << (p).first << " " << (p).second << endl;
#define printVP(vp)                                                            \\
  cerr << (#vp) << ":" << endl;                                                \\
  for (auto(p) : (vp)) {                                                       \\
    cerr << (p).first << " " << (p).second << endl;                            \\
  }

inline void output() { cerr << endl; }
template <typename First, typename... Rest>
inline void output(const First &first, const Rest &...rest) {
  cerr << first << " ";
  output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

struct Cake {
  int t;
  int h, w;
  Cake() {}
  Cake(int _t, int _h, int _w) : t(_t), h(_h), w(_w) {}
  bool operator<(const Cake &o) const {
    if (t != o.t)
      return t < o.t;
    return h * w < o.h * o.w;
  }
};

int n, h, w;
vector<Cake> vec;
int p, s;

void cut(int t) {
  Cake c = vec[p];
  vec.erase(vec.begin() + p);
  Cake c1 = c, c2 = c;
  c1.t = t;
  c2.t = t;
  s %= (c.h + c.w);
  if (s < c.w) {
    c1.w = s;
    c2.w = c.w - s;
  } else {
    s -= c.w;
    c1.h = s;
    c2.h = c.h - s;
  }
  vec.emplace_back(c1);
  vec.emplace_back(c2);
  sort(all(vec));
}

void solve() {
  vec.clear();
  vec.emplace_back(Cake(0, h, w));
  rep(i, n) {
    cin >> p >> s;
    p--;
    cut(i);
  }
  vi ans;
  for (auto c : vec) {
    ans.emplace_back(c.h * c.w);
  }
  sort(all(ans));
  cerr << "hey!" << endl;
  rep(i, ans.size()) { cout << (i ? " " : "") << ans[i]; }
  cout << endl;
}

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

  while (cin >> n >> w >> h, h) {
    solve();
  }
}