Zalmoxis
Time limit1sMemory limit512 MB
Insert K values into S to form a ZalSequence of length N+K, where each value v is a leaf at depth 30-v of a binary split tree.
- Level
Medium7 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Tanaka has become interested in Dacian mythology (the Dacians lived in the area of Romania before the Romans). In this mythology, Zalmoxis was the supreme god, and Pleistoros was the god of war. In Tanaka's new interpretation, Zalmoxis has a new powerful attack, the ZalPunch, and he loves ZalSequences.
The ZalPunch is an attack that can be applied to non-negative integer sequences. It takes a strictly positive integer from the sequence and replaces it with two occurrences of . For example:
[1]becomes[0, 0][1, 23, 3]becomes[1, 22, 22, 3]- But
[1, 3]does not become[2, 1, 2], since the order of the sequence matters.
ZalSequences are the sequences that Zalmoxis loves. A sequence is a ZalSequence if it is one of the following:
- The sequence
[30]. - A sequence that can be obtained by applying a ZalPunch to another ZalSequence.
For example, [30], [29, 29], and [29, 28, 27, 27] are ZalSequences, but [28, 29, 28] is not.
To begin with, Zalmoxis creates a ZalSequence of length . However, one of his enemies destroys of the values in this sequence, leaving remaining values. Call this sequence . Given , , and , insert values into to create any ZalSequence of length . It is guaranteed that this is possible in all test cases.
Input
The first line contains the positive integers and .
The next line contains non-negative integers, the values of .
Output
The only line of output contains a sequence of non-negative integers that is a ZalSequence and contains as a subsequence. The elements of appear at possibly non-consecutive positions in the output.
Constraints
- The sequence in the input is a subsequence of a ZalSequence of length .
Hints
In the first example, [29, 27, 25, 25, 26, 28] can be obtained from [30] by the following ZalPunches:
[30] → [29, 29] → [29, 28, 28] → [29, 27, 27, 28] → [29, 27, 26, 26, 28] → [29, 27, 25, 25, 26, 28]
In the second example, [29, 28, 27, 26, 25, 25] can be obtained from [30] by the following ZalPunches:
[30] → [29, 29] → [29, 28, 28] → [29, 28, 27, 27] → [29, 28, 27, 26, 26] → [29, 28, 27, 26, 25, 25]