Obedient Tom
InterviewTime limit1sMemory limit1024 MB
Simulate placing N colored toys into three capacity-K boxes, trying each toy's preferred box, then the next box in the A-B-C cycle when it is full.
- Level
Easy2 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
Tom has toys scattered around the room. His mother gave him three boxes for storing them. Each box holds toys, and the three boxes together have enough room for all of the toys.
Tom first decided on a simple rule. Blue toys go into box A, green toys go into box B, and red toys go into box C. Then he wondered what would happen if not every toy fit into the box for its color. So he added another rule: if a toy cannot go into box A, he tries box B instead. If it cannot go into B, he tries C instead of B, and if it cannot go into C, he tries A instead of C.
Input
The first line contains two integers and (, , ), the number of toys and the number of toys that fit in one box.
The second line contains a string of length made of the letters 's', 'r', and 'p'. The letters give the colors of the toys in the order they are placed into the boxes: 's' is blue, 'r' is green, and 'p' is red.
Output
Print three lines. The first line is the colors of the toys in box A, the second line is the colors of box B, and the third line is the colors of box C. In each line, the colors appear in the order the toys were placed into that box.