Prefix Medians
Time limit1sMemory limit128 MB
Given the prefix medians B of an unknown permutation of 1 to 2N-1, reconstruct the lexicographically smallest permutation that produces exactly those medians.
- Level
Hard8 of 10
- Topics
- Greedy, Implementation, Sorting, Brute force
- Solved
- No attempts yet
Problem
Let be a permutation of .
Define the prefix medians of as an array with elements, where is the median of the first elements .
The median of a list of numbers, where is odd, is the middle value after the list is sorted.
You are given and the array . Reconstruct a permutation whose prefix medians are exactly .
Input
The first line contains one integer .
The second line contains integers separated by spaces.
Output
Print as a single line of integers separated by spaces.
Several permutations may produce the same array ; among them, print the lexicographically smallest one. It is guaranteed that at least one valid permutation exists.
Constraints
- for each ()
- A permutation with prefix medians is guaranteed to exist.