The Tower of Ancient Stones
View as PDFThe Tower of Ancient Stones
Blocks arrive one at a time. A block is placed on the tower only if it is strictly smaller than the current top block (the first block always goes on).
Otherwise it is added to the discard pile.Output the discard pile contents in first-discarded to last-discarded order.
If the pile is empty, output EMPTY DISCARD.
Your Task
Given blocks arriving in a specified order, simulate the tower placement
rule and output the discard pile.
Input Specification
The first line contains — the number of simulations.
Each simulation starts with
on its own line, followed by
space-separated
integers (block values in arrival order).
Output Specification
For each simulation print the discarded values space-separated, or EMPTY DISCARD.
Sample Input
2
5
3 1 4 2 5
4
4 3 2 1
Sample Output
4 2 5
EMPTY DISCARD
Constraints
All block values are distinct positive integers.
Comments
what if the numbers are the same in the input?
Look at 2nd line of the problem statement, it may answer this.
A block is placed on the tower only if it is strictly smaller than the current top block ...
by far the hardest one of the original 6 problems
then you should check out the new problem Oracle Prophecy Counts... :-)