Eggs
Time limit1sMemory limit128 MB
Given eggs in four baskets, output the sequence of allowed two-remove-one-add operations that gathers all eggs into a single basket using the minimum number of steps.
- Level
Medium6 of 10
- Topics
- Greedy, Simulation, Math
- Solved
- No attempts yet
Problem
Eggs are divided among four baskets. One unit operation works as follows.
- Choose two distinct baskets A and B that each contain at least one egg.
- Remove one egg from A and one egg from B.
- Choose one basket different from both A and B, and put both removed eggs into that basket.
Starting from the initial state, print the basket states in order until all eggs are gathered in one basket. The number of unit operations should be as small as possible, and the given value K is the benchmark operation count used for judging.
Input
The first line contains the benchmark number of unit operations K. The second line contains four integers separated by spaces: the numbers of eggs in the four baskets. The total number of eggs is between 4 and 3000, inclusive.
Output
On the first line, print the initial basket state in the same format as the input. On each following line, print the basket state after one unit operation. The last line must be a state where all eggs are gathered in one basket. The number of unit operations you print is the number of state lines after the first line.