Problem D
Interview Queue
A very popular position has just opened up at Poodle Inc. Candidates have formed a queue while they wait for their turn to be interviewed.
Competition is fierce and each candidate knows that they will not be selected if another candidate is strictly better than them. Every minute, each candidate looks at the resumé of candidates who are currently adjacent to them in the queue (ahead and behind). If at least one of the neighbour’s resumé’s perceived value is strictly greater than their resumé’s perceived value, they leave the queue since they do not want to waste their time. The candidates all look at their neighbor’s resumé simultaneously, and then some candidates leave the queue simultaneously.
This process continues until no more candidates leave the queue. Determine the number of minutes that pass while this process takes place. Report the values of the candidates that leave the queue in each round. Also report the final state of the queue.
Input
The first line of input contains a single integer
The second line contains
Output
Display
Sample Input 1 | Sample Output 1 |
---|---|
10 3 6 2 3 2 2 2 1 5 6 |
2 3 2 2 1 5 3 2 2 6 6 |
Sample Input 2 | Sample Output 2 |
---|---|
3 17 17 17 |
0 17 17 17 |
Sample Input 3 | Sample Output 3 |
---|---|
7 8 1 2 3 5 6 7 |
2 1 2 3 5 6 7 8 |