alexjercan/bugnet huggingface dataset:
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9 + 7)
#define endl "\\n"

#define yn(f) ((f) ? "Yes" : "No")
#define YN(f) ((f) ? "YES" : "NO")

#define MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (true) {
    int N, M, r, q;
    int t, n, m, s;
    int ts, te;

    vector<vector<pair<int, int>>> pc;

    cin >> N >> M;

    if (!N && !M)
      break;
    cin >> r;

    pc.resize(M + 1);

    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      pc[m].push_back(make_pair(t, s));
    }
    for (int i = 1; i <= M; i++) {
      pc[i].push_back(make_pair(INF, 1));
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int res = 0;

      cin >> ts >> te >> m;

      res = te - ts;
      // cout<<res<<endl;
      for (int j = 0, con = 0, x = 0; j < pc[m].size(); j++) {
        if (!con && pc[m][j].second) {
          res -= max(0ll, min(pc[m][j].first, te) - max(ts, x));
          // cout<<i<<" "<<max(0ll, min(pc[m][j].first,te) - max(ts, x))<<"
          // "<<min(pc[m][j].first,te)<<" - "<<max(ts, x)<<endl;
        }
        // cout<<i<<" "<<j<<" "<<con<<" "<<pc[m][j].first<<endl;
        if (pc[m][j].second)
          con++;
        else
          con--;

        if (!con)
          x = pc[m][j].first;
      }

      cout << res << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

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

#define MAX 110

int main() {

  while (1) {
    int N, M, r, q, time[MAX][2000] = {};
    int t, n, m, s, ts, te;
    cin >> N >> M;
    if (!N && !M)
      break;
    cin >> r;
    for (int i = 1; i <= r; i++) {
      cin >> t >> n >> m >> s;
      if (!s) {
        time[n][t + 1] -= m;
      } else {
        time[n][t] += m;
      }
    }

    for (int j = 540; j <= 1260; j++) {
      for (int k = 1; k <= N; k++) { // cout<<time[k][j]<<" ";cout<<endl;
        time[k][j] += time[k][j - 1];
      }
    }
    /* for(int j = 780; j <= 870; j++){cout<<j<<" ";
       for(int k = 1; k <= N; k++)cout<<time[k][j]<<" ";cout<<endl;
     }*/

    cin >> q;
    for (int i = 1; i <= q; i++) {
      int ans = 0, temp = 0;
      cin >> ts >> te >> m;
      for (int j = ts; j <= te; j++) {
        for (int k = 1; k <= N; k++) {
          int l = j;
          if (time[k][j] == m) { // cout<<k<<" "<<j<<" "<<m<<endl;
            while (time[k][l] && l <= te)
              l++;
            ans += l - j - 1; // cout<<ans<<" "<<l<<" "<<j<<endl;
            if (m == time[k][j - 1] && j - 1 >= ts)
              ans++;
            j = l - 1;
            // temp = j;
            break;
          }
        }
      }
      cout << ans << endl;
    }
  }

  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

struct cake {
  int w, h, area;
};

bool operator<(const cake &lhs, const cake &rhs) { return lhs.area < rhs.area; }

vector<cake> cakes;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d && w && d) {
    cakes.push_back((cake){w, d, w * d});
    for (int i = 0; i < n; i++) {

      int p, s;
      cin >> p >> s;
      cake c = cakes[p - 1];
      cakes.erase(cakes.begin() + p - 1);
      s %= (c.w + c.h);
      if (s < c.w) {
        cakes.push_back((cake){c.w - s, c.h, (c.w - s) * c.h});
        cakes.push_back((cake){s, c.h, s * c.h});
      } else if (s > c.w) {
        s -= c.w;
        cakes.push_back((cake){c.w, c.h - s, c.w * (c.h - s)});
        cakes.push_back((cake){c.w, s, c.w * s});
      } else {
        cakes.push_back(c);
      }
      sort(cakes.begin() + i, cakes.begin() + i + 2);
    }
    sort(cakes.begin(), cakes.end());
    for (unsigned int i = 0; i < cakes.size(); i++)
      if (i == cakes.size() - 1)
        cout << cakes[i].area << endl;
      else
        cout << cakes[i].area << " ";

    cakes.clear();
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

struct cake {
  int w, h, area;
};

bool operator<(const cake &lhs, const cake &rhs) { return lhs.area < rhs.area; }
/*
bool operator== (cake &lhs, cake &rhs)
{
    return lhs.area == rhs.area;
}

bool operator> (cake &lhs, cake &rhs)
{
    return lhs.area > rhs.area;
}
*/

vector<cake> cakes;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d && w && d) {
    cakes.push_back((cake){w, d, w * d});
    for (int i = 0; i < n; i++) {

      int p, s;
      cin >> p >> s;
      cake c = cakes[p - 1];
      cakes.erase(cakes.begin() + p - 1);
      s %= (c.w + c.h);
      if (s < c.w) {
        cakes.push_back((cake){c.w - s, c.h, (c.w - s) * c.h});
        cakes.push_back((cake){s, c.h, s * c.h});
      } else if (s > c.w) {
        s -= c.w;
        cakes.push_back((cake){c.w, c.h - s, c.w * (c.h - s)});
        cakes.push_back((cake){c.w, s, c.w * s});
      } else {
        cakes.push_back(c);
      }
      sort(cakes.begin(), cakes.end());
    }
    for (int i = 0; i < cakes.size(); i++)
      if (i == cakes.size() - 1)
        cout << cakes[i].area << endl;
      else
        cout << cakes[i].area << " ";

    cakes.clear();
  }
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
struct squ {
  int w, h;
};

int main() {

  int n, w, d, p, s;
  while (true) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) {
      break;
    }
    vector<squ> data;
    data.push_back(squ({w, d}));
    for (int i = 1; i <= n; i++) {
      cin >> p >> s;
      p--;
      s %= (data[p].w + data[p].h);
      squ a, b;
      int h = data[p].h;
      int w = data[p].w;
      if (0 < s && s < w) {
        a.w = s;
        a.h = h;
        b.w = w - s;
        b.h = h;
      } else {
        a.w = w;
        a.h = w + h - s;
        b.w = w;
        b.h = s - w;
      }
      if (a.w * a.h > b.w * b.h) {
        swap(a.w, b.w);
        swap(a.h, b.h);
      }
      vector<squ> tmp;
      for (int j = 0; j < data.size(); j++) {
        if (j != p) {
          tmp.push_back(data[j]);
        }
      }
      tmp.push_back(a);
      tmp.push_back(b);
      data = tmp;
    }
    vector<int> v;
    for (int i = 0; i < data.size(); i++) {
      v.push_back(data[i].w * data[i].h);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size() - 1; i++) {
      cout << v[i] << " ";
    }
    cout << v[v.size() - 1] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  struct square {
    int w, h;
  };
  int n, w, d, p, s;
  while (true) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) {
      break;
    }
    square data[1000];
    data[1].w = w;
    data[1].h = d;
    for (int i = 1; i <= n; i++) {
      cin >> p >> s;

      s %= (data[p].w + data[p].h);
      square a, b;
      int h = data[p].h;
      int w = data[p].w;
      if (0 < s && s < w) {
        a.w = s;
        a.h = h;
        b.w = w - s;
        b.h = h;
      } else {
        a.w = w;
        a.h = w + h - s;
        b.w = w;
        b.h = s - w;
      }
      if (a.w * a.h > b.w * b.h) {
        swap(a.w, b.w);
        swap(a.h, b.h);
      }
      data[p] = a;
      data[i + 1] = b;
    }
    vector<int> v;
    for (int i = 1; i <= n + 1; i++) {
      v.push_back(data[i].w * data[i].h);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size() - 1; i++) {
      cout << v[i] << " ";
    }
    cout << v[v.size() - 1] << endl;
  }

  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct P {
  int T, X, Y, W, H;
  P(int T = 0, int X = 0, int Y = 0, int W = 0, int H = 0)
      : T(T), X(X), Y(Y), W(W), H(H) {}
  bool operator<(const P &p) const {
    if (T != p.T)
      return T < p.T;
    return W * H < p.W * p.H;
  }
  pair<P, P> cut(int s, int t) {
    T = t;
    s %= 2 * W + 2 * H;
    assert(s != 0);
    assert(s != W);
    assert(s != W + H);
    assert(s != W + W + H);
    if (s < W) {
      return make_pair(P(t, X, Y, s, H), P(t, X + s, Y, W - s, H));
    }
    if (s < W + H) {
      s -= W;
      return make_pair(P(t, X, Y, W, s), P(t, X, Y + s, W, H - s));
    }
    if (s < W + W + H) {
      s = W - (s - (W + H));
      return make_pair(P(t, X, Y, s, H), P(t, X + s, Y, W - s, H));
    }
    if (s < W + W + H + H) {
      s = H - (s - (W + W + H));
      return make_pair(P(t, X, Y, W, s), P(t, X, Y + s, W, H - s));
    }
    assert(0);
  }
};

int main() {
  int N, W, D;
  while (cin >> N >> W >> D, W) {
    vector<P> V;
    V.push_back(P(0, 0, 0, W, D));
    for (int i = 0; i < N; i++) {
      int p, s;
      cin >> p >> s;
      p--;
      pair<P, P> npp = V[p].cut(s, i + 1);
      V[p] = npp.first;
      V.push_back(npp.second);
      sort(V.begin(), V.end());
    }
    sort(V.begin(), V.end(),
         [](const P &a, const P &b) { return a.W * a.H < b.W * b.H; });
    for (int i = 0; i <= N; i++) {
      if (i)
        printf(" ");
      printf("%d", V[i].W * V[i].H);
    }
    puts("");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct P {
  int T, X, Y, W, H;
  P(int T = 0, int X = 0, int Y = 0, int W = 0, int H = 0)
      : T(T), X(X), Y(Y), W(W), H(H) {}
  bool operator<(const P &p) const {
    if (T != p.T)
      return T < p.T;
    return W * H < p.W * p.H;
  }
  P cut(int s, int t) {
    T = t;
    s %= 2 * W + 2 * H;
    assert(s != 0);
    assert(s != W);
    assert(s != W + H);
    assert(s != W + W + H);
    if (s < W) {
      P np(t, X + s, Y, W - s, H);
      W = s;
      return np;
    }
    if (s < W + H) {
      P np(t, X, Y + s, W, H - s);
      H = s;
      return np;
    }
    if (s < W + W + H) {
      s = W - (s - (W + H));
      P np(t, X + s, Y, W - s, H);
      W = s;
      return np;
    }
    if (s < W + W + H + H) {
      s = H - (s - (W + W + H));
      P np(t, X, Y + s, W, H - s);
      H = s;
      return np;
    }
    assert(0);
  }
};

int main() {
  int N, W, D;
  while (cin >> N >> W >> D, W) {
    vector<P> V;
    V.push_back(P(0, 0, 0, W, D));
    for (int i = 0; i < N; i++) {
      int p, s;
      cin >> p >> s;
      p--;
      P np = V[p].cut(s, i + 1);
      V.push_back(np);
      sort(V.begin(), V.end());
    }
    vector<int> ans(N + 1);
    for (int i = 0; i <= N; i++)
      ans[i] = V[i].W * V[i].H;
    sort(ans.begin(), ans.end());
    for (int i = 0; i <= N; i++) {
      if (i)
        printf(" ");
      printf("%d", ans[i]);
    }
    puts("");
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

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

typedef pair<int, int> P;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d, n || w || d) {
    vector<P> v;
    v.push_back(P(w, d));
    int count = 1;
    while (n--) {
      int p, s;
      cin >> p >> s;

      int x = v[p - 1].first, y = v[p - 1].second;
      int len = x * 2 + y * 2;
      s %= len;

      int x1, x2, y1, y2;
      if (s < x) {
        x1 = s;
        x2 = x - s;
        y1 = y2 = y;
      } else if (s < len / 2) {
        x1 = x2 = x;
        y1 = s - x;
        y2 = y - y1;
      } else if (s < len - y) {
        x1 = s - (len / 2);
        x2 = x - x1;
        y1 = y2 = y;
      } else if (s < len) {
        x1 = x2 = x;
        y1 = len - s;
        y2 = y - y1;
      }

      if (x1 * y1 < x2 * y2) {
        v.push_back(P(x1, y1));
        v.push_back(P(x2, y2));
      } else {
        v.push_back(P(x2, y2));
        v.push_back(P(x1, y1));
      }
      count++;
      v.erase(v.begin() + (p - 1));

      v.resize(count);
    }

    vector<int> res;
    for (auto i : v) {
      res.push_back(i.first * i.second);
    }

    sort(res.begin(), res.end());

    for (int i = 0; i < res.size() - 1; i++) {
      cout << res[i] << " ";
    }
    cout << res[res.size() - 1] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

typedef pair<int, int> P;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d, n || w || d) {
    vector<P> v;
    v.push_back(P(w, d));
    int count = 1;
    while (n--) {
      int p, s;
      cin >> p >> s;

      int x = v[p - 1].first, y = v[p - 1].second;
      int len = x * 2 + y * 2;
      s %= len;

      int x1, x2, y1, y2;
      if (s < x) {
        x1 = s;
        x2 = x - s;
        y1 = y2 = y;
      } else if (s < len / 2) {
        x1 = x2 = x;
        y1 = (len / 2) - s;
        y2 = y - y1;
      } else if (s < 2 * x + y) {
        x1 = s;
        x2 = x - s;
        y1 = y2 = y;
      } else if (s < len) {
        x1 = x2 = x;
        y1 = len - s;
        y2 = y - y1;
      }

      v.erase(v.begin() + (p - 1));
      if (x1 * y1 < x2 * y2) {
        v.insert(v.begin() + (p - 1), P(x2, y2));
        v.insert(v.begin() + (p - 1), P(x1, y1));
      } else {
        v.insert(v.begin() + (p - 1), P(x1, y1));
        v.insert(v.begin() + (p - 1), P(x2, y2));
      }
      count++;
      v.resize(count);
    }

    vector<int> res;
    for (auto i : v) {
      res.push_back(i.first * i.second);
    }

    sort(res.begin(), res.end());

    for (int i = 0; i < res.size() - 1; i++) {
      cout << res[i] << " ";
    }
    cout << res[res.size() - 1] << endl;
  }

  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct P {
  int h;
  int w;
  int s;
};

bool comp(const P &p1, const P &p2) { return p1.s < p2.s; }

int main() {
  int n, w, d, s, t;
  P p, q;

  while (cin >> n >> w >> d && (n + w + d)) {
    vector<P> vec;
    p.w = w;
    p.h = d;
    p.s = w * d;
    vec.push_back(p);
    while (n--) {
      cin >> t >> s;
      p = vec[t - 1];
      vec.erase(vec.begin() + (t - 1));
      s %= (p.h * 2 + p.w * 2);
      if (0 < s && s < p.w) {
        q.h = p.h;
        q.w = p.w - s;
        p.w = s;
      } else if (p.w < s && s < p.w + p.h) {
        q.w = p.w;
        s -= p.w;
        q.h = p.h - s;
        p.h = s;
      } else if (p.w + p.h < s && s < 2 * p.w + p.h) {
        q.h = p.h;
        s -= (p.w + p.h);
        q.w = p.w - s;
        p.w = s;
      } else {
        q.w = p.w;
        s -= (2 * p.w + p.h);
        q.h = p.h - s;
        p.h = s;
      }
      q.s = q.h * q.w;
      p.s = p.w * p.h;

      if (p.s < q.s) {
        vec.push_back(p);
        vec.push_back(q);
      } else {
        vec.push_back(q);
        vec.push_back(p);
      }
    }
    sort(vec.begin(), vec.end(), comp);

    cout << vec[0].s;
    for (int i = 1; i < vec.size(); i++) {
      cout << " " << vec[i].s;
    }
    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct P {
  int h;
  int w;
};

bool operator<(const P &p1, const P &p2) { return p1.h * p1.w < p2.h * p2.w; }

int main() {
  int n, w, h, s, t;
  P p, q;

  while (cin >> n >> w >> h) {
    if (n == 0 && w == 0 && h == 0) {
      break;
    }
    vector<P> vec;
    p.h = h;
    p.w = w;
    vec.push_back(p);

    while (n--) {
      cin >> s >> t;
      s--;
      p = vec[s];

      t = t % (2 * p.h + 2 * p.w);
      if (t < p.w) {
        p.w -= t;
        q.w = t;
        q.h = p.h;
      } else if (t < p.w + p.h) {
        t -= p.w;
        p.h -= t;
        q.h = t;
        q.w = p.w;
      } else if (t < 2 * p.w + p.h) {
        t -= (p.w + p.h);
        p.w -= t;
        q.w = t;
        q.h = p.h;
      } else {
        t -= (2 * p.w + p.h);
        p.h -= t;
        q.h = t;
        q.w = p.w;
      }

      vec[s] = p;
      if (p.w * p.h > q.w * q.h) {
        vec.insert((vec.begin() + s), q);
      } else {
        vec.insert((vec.begin() + (s + 1)), q);
      }
    }
    sort(vec.begin(), vec.end());

    cout << (vec[0].h * vec[0].w);
    for (int i = 1; i < vec.size(); i++) {
      cout << " " << (vec[i].h * vec[i].w);
    }
    cout << endl;
    vec.clear();
  }

  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int INF = 1 << 29, MOD = 1e9 + 7;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d && w) {
    pair<int, int> p[n + 2];
    p[1] = make_pair(w, d);
    for (int i = 2; i < n + 2; i++) {
      int num, len;
      cin >> num >> len;
      int width = p[num].first, depth = p[num].second;
      int cut = len % (width + depth);
      for (int j = num + 1; j < i; j++) {
        p[j - 1] = p[j];
      }
      if (cut <= width) {
        p[i - 1] = make_pair(min(cut, width - cut), depth);
        p[i] = make_pair(max(cut, width - cut), depth);
      } else {
        cut -= width;
        p[i - 1] = make_pair(width, min(cut, depth - cut));
        p[i] = make_pair(width, max(cut, depth - cut));
      }
    }
    // rep(i,n) cout<<p[i+1].first<<" "<<p[i+1].second<<endl;
    int ans[n + 1];
    rep(i, n + 1) { ans[i] = p[i + 1].first * p[i + 1].second; }
    sort(ans, ans + n + 1);
    rep(i, n + 1) i ? cout << " " << ans[i] : cout << ans[i];
    cout << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int INF = 1 << 29, MOD = 1e9 + 7;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d && w) {
    pair<int, int> p[n + 2];
    p[1] = make_pair(w, d);
    for (int i = 2; i < n + 2; i++) {
      int num, len;
      cin >> num >> len;
      int wide = p[num].first, depth = p[num].second;
      int cut = len % (wide + depth);
      if (cut < wide) {
        p[num] = make_pair(min(cut, wide - cut), depth);
        p[i] = make_pair(max(cut, wide - cut), depth);
      } else {
        cut -= wide;
        p[num] = make_pair(wide, min(cut, depth - cut));
        p[i] = make_pair(wide, max(cut, depth - cut));
      }
    }
    // rep(i,n) cout<<p[i+1].first<<" "<<p[i+1].second<<endl;
    int ans[n + 1];
    rep(i, n + 1) { ans[i] = p[i + 1].first * p[i + 1].second; }
    sort(ans, ans + n + 1);
    rep(i, n + 1) i ? cout << " " << ans[i] : cout << ans[i];
    cout << endl;
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, w, d;
  while (1) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0)
      break;
    vector<pair<int, int>> cake;
    cake.push_back(make_pair(w, d));
    for (int i = 0; i < n; i++) {
      int p, s;
      cin >> p >> s;
      pair<int, int> nowcake = cake[p - 1];
      w = nowcake.first;
      d = nowcake.second;
      if (w == 0 || d == 0)
        cout << i << " " << w << " " << d << endl;
      s = s % (w + d);
      if (s < w) {
        cake.push_back(make_pair(min(s, w - s), d));
        cake.push_back(make_pair(max(s, w - s), d));
      } else {
        s -= w;
        cake.push_back(make_pair(w, min(s, d - s)));
        cake.push_back(make_pair(w, max(s, d - s)));
      }
      cake.erase(cake.begin() + p - 1);
    }
    vector<int> result;
    for (int i = 0; i < cake.size(); i++) {
      result.push_back(cake[i].first * cake[i].second);
    }
    sort(result.begin(), result.end());
    for (int i = 0; i < result.size(); i++) {
      if (i != 0)
        cout << " ";
      cout << result[i];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, w, d;
  while (1) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0)
      break;
    vector<pair<int, int>> cake;
    cake.push_back(make_pair(w, d));
    for (int i = 0; i < n; i++) {
      int p, s;
      cin >> p >> s;
      pair<int, int> nowcake = cake[p - 1];
      w = nowcake.first;
      d = nowcake.second;
      s = s % (w + d);
      if (s < w) {
        cake.insert(cake.begin() + p, make_pair(max(s, w - s), d));
        cake.insert(cake.begin() + p, make_pair(min(s, w - s), d));

      } else {
        s -= w;
        cake.insert(cake.begin() + p, make_pair(w, max(s, d - s)));
        cake.insert(cake.begin() + p, make_pair(w, min(s, d - s)));
      }
      cake.erase(cake.begin() + p - 1);
    }
    vector<int> result;
    for (int i = 0; i < cake.size(); i++) {
      result.push_back(cake[i].first * cake[i].second);
    }
    sort(result.begin(), result.end());
    for (int i = 0; i < result.size(); i++) {
      if (i != 0)
        cout << " ";
      cout << result[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, w, d, p, s, w1, d1;
  vector<pair<int, pair<int, int>>> v;
  pair<int, pair<int, int>> cut;

  while (1) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0)
      break;
    v.clear();
    v.push_back(make_pair(w * d, make_pair(w, d)));
    for (int i = 0; i < n; i++) {
      cin >> p >> s;
      cut = v[p - 1];
      v.erase(v.begin() + p - 1);
      w1 = cut.second.first;
      d1 = cut.second.second;
      s = s % (w1 + d1);
      if (w1 > s) {
        if (s < w1 - s) {
          v.push_back(make_pair(d1 * s, make_pair(s, d1)));
          v.push_back(make_pair(d1 * (w1 - s), make_pair(w1 - s, d1)));
        } else {
          v.push_back(make_pair(d1 * (w1 - s), make_pair(w1 - s, d1)));
          v.push_back(make_pair(d1 * s, make_pair(s, d1)));
        }
      } else {
        if (s - w1 < d1 + w1 - s) {
          v.push_back(make_pair(w1 * (s - w1), make_pair(w1, s - w1)));
          v.push_back(
              make_pair(w1 * (d1 + w1 - s), make_pair(w1, d1 + w1 - s)));
        } else {
          v.push_back(
              make_pair(w1 * (d1 + w1 - s), make_pair(w1, d1 + w1 - s)));
          v.push_back(make_pair(w1 * (s - w1), make_pair(w1, s - w1)));
        }
      }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size() - 1; i++) {
      cout << v[i].first << " ";
    }
    cout << v[v.size() - 1].first << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, w, d, p, s, w1, d1;
  vector<pair<int, pair<int, int>>> v;
  pair<int, pair<int, int>> cut;

  while (1) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0)
      break;
    v.clear();
    v.push_back(make_pair(w * d, make_pair(w, d)));
    for (int i = 0; i < n; i++) {
      cin >> p >> s;
      cut = v[p - 1];
      v.erase(v.begin() + p - 1);
      w1 = cut.second.first;
      d1 = cut.second.second;
      s = s % (w1 + d1);
      if (w1 > s) {
        v.push_back(make_pair(d1 * s, make_pair(s, d1)));
        v.push_back(make_pair(d1 * (w1 - s), make_pair(w1 - s, d1)));
      } else {
        v.push_back(make_pair(w1 * (s - w1), make_pair(w1, s - w1)));
        v.push_back(make_pair(w1 * (d1 + w1 - s), make_pair(w1, d1 + w1 - s)));
      }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      cout << v[i].first << " ";
    }
    cout << endl;
  }
  return 0;
}