- やるだけ
- ケーキに番号を振るやり方を間違えてREを連発してしまった
struct Piece {
int x, y;
Piece() { }
Piece(int x, int y) : x(x), y(y) { }
};
int main() {
for (int n, w, d; cin >> n >> w >> d && (n || w || d); ) {
vector<Piece> ps;
ps.push_back(Piece());
ps.push_back(Piece());
ps.back().x = w;
ps.back().y = d;
REP(i, n) {
int p, s;
cin >> p >> s;
s %= ps[p].x + ps[p].y;
if (s < ps[p].x) {
int x = ps[p].x - s;
if (x < s) {
swap(x, s);
}
Piece p0(s, ps[p].y);
Piece p1(x, ps[p].y);
ps.erase(ps.begin() + p, ps.begin() + p + 1);
ps.push_back(p0);
ps.push_back(p1);
} else {
s -= ps[p].x;
int y = ps[p].y - s;
if (y < s) {
swap(y, s);
}
Piece p0(ps[p].x, s);
Piece p1(ps[p].x, y);
ps.erase(ps.begin() + p, ps.begin() + p + 1);
ps.push_back(p0);
ps.push_back(p1);
}
}
vector<int> areas;
for (int i = 1; i < ps.size(); ++i) {
areas.push_back(ps[i].x * ps[i].y);
}
sort(ALL(areas));
REP(i, areas.size()) {
if (i) {
cout << " ";
}
cout << areas[i];
}
cout << endl;
}
}