#C1900. Construct Max Heap

    ID: 45157 Type: Default 1000ms 256MiB

Construct Max Heap

Construct Max Heap

You are given a list of n unique integers. Your task is to construct a max heap from these integers and then output its level-order traversal. In a max heap, for every node at index i (starting from 0), its children (if they exist) located at indices 2i+1 and 2i+2 satisfy the condition:

$$A[i] \ge A[2i+1] \quad \text{and} \quad A[i] \ge A[2i+2]$$

For this problem, the level-order traversal of the heap is equivalent to printing the integers in descending order.

Note: Input is provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line contains an integer n which denotes the number of elements. The second line contains n space-separated unique integers.

outputFormat

Print the level-order traversal of the constructed max heap as a single line of space-separated integers.## sample

8
7 15 5 10 20 3 8 6
20 15 10 8 7 6 5 3