is part of the robotics team in his school. During one of the meetings after school, a sketchy person was wandering around and came into the robotics room. This person sees a storage bin full of the VEX Starstruck jacks and immediately becomes obsessed with them. sees this and tells him that he can disassemble one of the jacks by squeezing them. The person does so, and the jack breaks into pieces.
Due to the sketchy nature of this person and his obsession with the jacks, he begins to take jacks from the storage bin one by one, and squeezing them. This frenzied period continues for seconds.
Every second, the person does one of two possible actions:
T
: Takes one jack out from the storage bin, and places it on the table.B q
: Breaks each jack or piece that's currently on the table intoq
pieces, and puts them on the floor. When the table is empty, transfer all the pieces on the floor back onto the table.
prevent integer overflow allow to finish the work that was assigned by his English teacher, he decides that he will consider a jack "dust" if the jack is broken into strictly greater than pieces, and he will not be gluing them back together.
needs to figure out how many pieces each jack has been broken into, to assist him in gluing together the jacks that the person broke.
Since
is quite busy building the robot, can you help him figure this out?Input Specification
The first line will contain the integers , and , representing the number of modifications done by the sketchy person, the number of jacks in the storage bin, and the dust threshold respectively.
The next lines represent the operations. Each line will contain either just a character T
, or a character followed by an integer B q
, where is the integer.
Constraints
For all subtasks:
, for each
Subtask 1 [50%]
Subtask 2 [50%]
Output Specification
Output the number of pieces each jack has been broken into, in the order they were taken out of the storage bin.
If a jack has been considered as dust, output dust
.
Sample Input
7 4 5
T
T
B 2
B 3
T
B 4
T
Sample Output
dust
dust
4
1
Explanation
The person did operations on the jacks that were in the storage bin, and will consider any jacks that got broken up into more than pieces as "dust".
- The person takes out a jack from the bin and puts it on the table.
- He takes out another jack. (Same operation as above)
- He breaks each of the 2 jacks into 2 pieces, resulting in broken pieces for the first jack and broken pieces for the second jack.
- He then breaks each piece into 3 new pieces, resulting in broken pieces for the first jack and broken pieces for the second jack.
- He takes out another jack.
- He then breaks each piece into 4 new pieces, resulting in broken pieces for the first jack, broken pieces for the second jack, and 4 broken pieces for the third jack.
- He takes out another jack.
In the end, he took out 4 jacks, the first 2 were broken into pieces each and therefore considered as "dust" by . The third jack was broken into pieces, and the fourth jack was not broken, therefore it remains as piece.
Comments
Why am I MLEing?
I'm not sure but I think it's due to your product function. My guess is that as gets really large, you're essentially performing something along the lines of a manual factorial or exponent function and storing all the steps.
If the table becomes empty while breaking the pieces, do I move the pieces from the floor to the table?
Don't worry about the floor thing. Just assume that the pieces stay on the table at all times. Don't move anything to the floor.
Currently only 1 python submission has passed with question in time(from the mighty D). Would it be possible to get a time extension for python
It wasn't an issue with the language. Your solution's time complexity is too slow for the constraints.
I know realise that, thank you