#K46047. Block Stacker Simulation
Block Stacker Simulation
Block Stacker Simulation
You are given a board with a specified width W (i.e., number of columns) and a maximum height H for each column. You will receive a series of instructions where each instruction consists of a column number and a number of blocks to add. When adding blocks, the height of the column increases by the given number but cannot exceed H. After all instructions are processed, output the final heights of all columns.
Details:
- The board initially has all columns at height 0.
- For each instruction, if the current height of the specified column plus the given number of blocks exceeds H, then the column height is capped at H.
The relation used can be expressed in LaTeX as follows:
$$height = \min(\text{current height} + \text{blocks},\, H) $$Compute and output the final heights for each test case.
inputFormat
The input is read from standard input (stdin) and has the following format:
T W H N C1 B1 C2 B2 ... CN BN (repeated for each test case)
Where:
- T is the number of test cases.
- For each test case, the first line contains two integers: W (the number of columns) and H (the maximum height allowed for a column).
- The next line contains an integer N, the number of instructions.
- Then follow N lines, each containing two integers: C (the zero-indexed column number) and B (the number of blocks to add to that column).
outputFormat
For each test case, print a single line containing W space-separated integers representing the final heights of the columns after processing all instructions.
## sample5
3 5
4
0 1
1 2
2 3
1 2
4 10
5
0 4
3 3
2 2
1 3
0 1
2 3
4
0 2
1 1
0 2
1 5
5 1
5
0 1
1 1
2 1
3 1
4 1
3 2
6
0 2
1 2
2 2
0 2
1 2
2 2
1 4 3
5 3 2 3
3 3
1 1 1 1 1
2 2 2
</p>