#P6721. [BalkanOI 2011] medians
[BalkanOI 2011] medians
Description
Let be any permutation of .
We define the prefix medians of as a sequence of length , where is the median of .
You will be given the sequence . Please construct a sequence such that its prefix medians are exactly .
Input Format
The first line contains an integer .
The next line contains integers, representing the sequence .
Output Format
Output one line with integers, representing the sequence you construct.
The testdata is guaranteed to have a solution; you only need to output any one valid solution.
5
1 3 3 4 5
1 9 3 2 4 8 7 5 6
Hint
Constraints
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , and the testdata is guaranteed to have a solution.
Notes
This problem is translated from Balkan Olympiad in Informatics 2011 Day 1 T3 medians.
Thanks to
https://www.luogu.com.cn/user/193198
ing the SPJ.
Translated by ChatGPT 5
京公网安备 11011102002149号