Harry Potter and the Hall of Prophecy
InterviewTime limit2sMemory limit1024 MB
Repeatedly pick the closest remaining pair of 2n potions (ties go to the larger sum) and print the stronger of each pair for Neville and the weaker for Harry.
- Level
Medium5 of 10
- Topics
- Sorting, Heap, Linked list, Greedy
- Solved
- No attempts yet
Statement
Dumbledore's army is getting ready to fly to the Department of Mysteries at the Ministry of Magic. Voldemort's servants may be waiting on the way to the Prophecy, so Harry and Neville have decided to practice dueling.
They plan to hold rounds of duels. After each round, they drink a restorative potion so they do not waste strength. In total they have potions. After each round, they pick two potions whose powers are closest to each other. If several such pairs exist, they choose the pair with the largest sum of powers. Then Neville drinks the stronger potion of the pair, and Harry drinks the weaker one.
Help Harry and Neville determine which potions each of them drinks and in what order.
Input
The first line contains one integer (), the number of duel rounds. The second line contains integers (), where is the power of the -th restorative potion.
Output
On the first line, print the powers of the potions that Neville drinks. On the second line, print the powers of the potions that Harry drinks. The potions must be printed in the order in which Neville and Harry drink them.