#K66067. Plate Removal
Plate Removal
Plate Removal
Given a stack of plates arranged from top to bottom, remove plates from the top until the plate originally at the target position is at the top.
More formally, you are given a list of integers representing the stack of plates where the first element is on top. Also, an integer target is provided (1-indexed). Remove the first target - 1
plates from the stack, and output the removed plates in the order they were removed.
If target
is 1, then no plate is removed and the output should be an empty line.
Note: All positions are 1-indexed and the input is taken from standard input.
inputFormat
The input is read from stdin and consists of three lines:
- The first line contains an integer
n
, the number of plates. - The second line contains
n
space-separated integers representing the plates from top to bottom. - The third line contains an integer representing the target position (1-indexed).
outputFormat
Output the sequence of removed plates as space-separated integers on a single line. If no plates are removed, output an empty line.
## sample5
10 20 30 40 50
3
10 20