High Jump
Time limit1sMemory limit256 MB
Reconstruct each height's clears and misses from the recorded attempt order and report the top three jumpers under the countback tiebreak.
- Level
Hard8 of 10
- Topics
- Simulation, Backtracking
- Solved
- No attempts yet
Problem
jumpers, numbered 1 to , take part in a high jump competition.
At every height a jumper has three attempts. An attempt succeeds if the crossbar is still in place after the jumper leaves the landing area. A height is jumped in rounds. In one round every jumper who has not cleared the current height yet and is still in the competition jumps once, in increasing order of ID. A jumper who clears the height makes no further attempt at it. A jumper who misses all three attempts at a height is out of the competition. Carrying an attempt over to the next height is not allowed, and neither is passing a height or skipping an attempt. The bar is raised only after every jumper has finished the current height, and every jumper still in the competition jumps at every height.
The winner is the jumper who clears the greatest height. When several jumpers reach the same place, the order between them is decided by:
- the fewest misses at the height where the tie happened,
- then the fewest misses at the height before it, and so on back to the first height,
- then the smallest ID (a smaller ID means a higher seed).
A device around the landing area records the ID of every jumper who jumps, so the order of all attempts is known. The record covers the whole competition, from the first attempt to the attempt that puts the last jumper out. Read the record and report the three jumpers who take the awarded places.
The record matches at least one competition that follows these rules, and every competition matching the record awards the same three places.
Input
The first line has the number of jumpers () and the number of attempts ().
The second line has integers separated by single spaces, the IDs of the jumpers in the order the device recorded them.
Output
Print the IDs of the first, second and third place jumpers on one line, separated by spaces.
Note
In the first example jumper 1 clears the opening height on the first attempt and jumper 4 clears it on the second, while jumpers 2, 3 and 5 miss all three attempts and go out. At the next height jumpers 1 and 4 both miss three times, so they cleared the same height. At the height both of them cleared, jumper 1 has no miss and jumper 4 has one, so jumper 1 takes first place. Third place goes to jumper 2, the smallest ID among the three who went out first.