#P1905. Balanced Goods Distribution
Balanced Goods Distribution
Balanced Goods Distribution
In the ancient port of Genoa, there are three kinds of goods — pottery, furniture and marble — with weights of , , and units respectively. In total there are goods (where , with , , being the counts of pottery, furniture and marble respectively). There are also ships at Capua waiting to be loaded. Your task is to partition all the goods into piles subject to the following rules:
-
In each pile, the weights (representing a good) arranged from bottom to top must be strictly decreasing. (For example, marble (weight ) cannot be stacked on top of furniture or pottery.)
-
The difference between the total weights of any two piles cannot exceed units.
A valid solution always exists under the input constraints (note that since each pile can contain at most one of each type of goods, the maximum number of items in a pile is , and hence ). Output any one valid stacking scheme.
inputFormat
The input consists of a single line containing four integers separated by spaces:
- a: the number of pottery items (each weighing 1 unit),
- b: the number of furniture items (each weighing 2 units),
- c: the number of marble items (each weighing 3 units),
- p: the number of piles (ships).
It is guaranteed that a solution exists and that .
outputFormat
The output should describe a valid distribution of goods into piles. The first line should contain integers separated by spaces, where each integer represents the total weight of one pile. This is followed by lines, each line describing one pile. For each pile, list the weights of goods from bottom to top (separated by a space). Note that each pile must follow the strictly decreasing rule and the maximum difference between the total weights of any two piles must not exceed 3.
sample
3 3 3 3
6 6 6
3 2 1
3 2 1
3 2 1
</p>