Time limit
2s
Memory limit
128 MB
Dongho wants to pack ceramic decorative plates that all have the same width. Each plate is given as a grid with height h and width w; X is a cell occupied by the plate, and . is empty space.
A box has the same width as the plates, so plates cannot be rotated or shifted left or right. The plates are stacked in the input order inside boxes.
When a new plate is placed in the current box, it keeps its shape and is lowered from above. It is placed at the lowest vertical position where none of its X cells overlap an X cell already in the box. Only X cells are used for overlap checks, but after placement, the stack height includes the full h rows of the newly placed plate.
If placing the new plate this way would make the total height in the box exceed b, the current box is closed and that plate starts a new box from the bottom. After all plates are processed in order, compute the final height of each box.
The first line contains three natural numbers n, w, and b, separated by spaces. All three values are at most 100.
n is the number of plates, w is the width of both the plates and the boxes, and b is the height limit of a box.
Then the descriptions of n plates follow. For each plate, the first line contains its height h, where 1 <= h <= 10 and h <= b. The next h lines contain strings of length w, given from the top row to the bottom row. Each character is either . or X.
Print one integer for each box used. Each integer is the final height of that box, and the heights must be printed in the order the boxes are created, separated by spaces.