Problem p00730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define Rrep(i, a, n) for (int i = (a); i < (n); i++)
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int n, w, d;

  while (cin >> n >> w >> d, n || w || d) {
    int p[101], s[101];
    Rep(i, n) cin >> p[i] >> s[i], p[i]--;

    vector<Pii> cake;
    cake.pb(Pii(d, w));

    Rep(i, n) {
      // Rep(j, (int)cake.size()) cout << cake[j].sc << " " << cake[j].fr <<
      // endl; cout << endl;
      d = cake[p[i]].fr;
      w = cake[p[i]].sc;
      cake.erase(cake.begin() + p[i]);
      int mi;
      if (s[i] > (2 * w + 2 * d))
        s[i] /= (2 * w + 2 * d);
      if (s[i] < w) {
        mi = min(s[i], w - s[i]);
        cake.pb(Pii(d, mi));
        cake.pb(Pii(d, w - mi));
      } else if (s[i] < w + d) {
        s[i] -= w;
        mi = min(s[i], d - s[i]);
        cake.pb(Pii(mi, w));
        cake.pb(Pii(d - mi, w));
      } else if (s[i] < 2 * w + d) {
        s[i] -= w + d;
        mi = min(s[i], w - s[i]);
        cake.pb(Pii(d, mi));
        cake.pb(Pii(d, w - mi));
      } else {
        s[i] -= 2 * w + d;
        mi = min(s[i], d - s[i]);
        cake.pb(Pii(mi, w));
        cake.pb(Pii(d - mi, w));
      }
    }

    vector<int> ans;
    Rep(i, (int)cake.size()) ans.pb(cake[i].fr * cake[i].sc);
    sort(All(ans));
    Rep(i, (int)ans.size() - 1) cout << ans[i] << " ";
    cout << ans[ans.size() - 1] << endl;
  }
  return 0;
}

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

#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define Rrep(i, a, n) for (int i = (a); i < (n); i++)
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int n, w, d;

  while (cin >> n >> w >> d, n || w || d) {
    int p[101], s[101];
    Rep(i, n) cin >> p[i] >> s[i], p[i]--;

    vector<Pii> cake;
    cake.pb(Pii(d, w));

    Rep(i, n) {
      // Rep(j, (int)cake.size()) cout << cake[j].sc << " " << cake[j].fr <<
      // endl; cout << endl;
      d = cake[p[i]].fr;
      w = cake[p[i]].sc;
      cake.erase(cake.begin() + p[i]);
      int mi;
      s[i] %= 2 * w + 2 * d;
      if (s[i] < w) {
        mi = min(s[i], w - s[i]);
        cake.pb(Pii(d, mi));
        cake.pb(Pii(d, w - mi));
      } else if (s[i] < w + d) {
        s[i] -= w;
        mi = min(s[i], d - s[i]);
        cake.pb(Pii(mi, w));
        cake.pb(Pii(d - mi, w));
      } else if (s[i] < 2 * w + d) {
        s[i] -= w + d;
        mi = min(s[i], w - s[i]);
        cake.pb(Pii(d, mi));
        cake.pb(Pii(d, w - mi));
      } else {
        s[i] -= 2 * w + d;
        mi = min(s[i], d - s[i]);
        cake.pb(Pii(mi, w));
        cake.pb(Pii(d - mi, w));
      }
    }

    vector<int> ans;
    Rep(i, (int)cake.size()) ans.pb(cake[i].fr * cake[i].sc);
    sort(All(ans));
    Rep(i, (int)ans.size() - 1) cout << ans[i] << " ";
    cout << ans[ans.size() - 1] << endl;
  }
  return 0;
}