Genome
Time limit1sMemory limit128 MB
Build the lexicographically smallest sequence that is l adjacent swaps from the first genome and k-l swaps from the second.
- Level
Hard9 of 10
- Topics
- Greedy, Segment tree, Sorting
- Solved
- No attempts yet
Problem
The genetic information of Byteotian organisms, unlike that of Earth organisms, is encoded not by four but by different chemical compounds called byteacids. A single joined chain of byteacids is called a BNA.
A BNA is especially prone to inversion mutations: one such mutation swaps two adjacent byteacids. Using a theoretical model, the great biotechnologist Byteazar discovered that inversion mutations alone can turn a Byteotian cucumber into a tomato, and that exactly inversions of the cucumber's BNA are both necessary and sufficient to do so.
The scientists fix a natural number with and want to build an organism that is a tomato in an fraction and a cucumber in the rest. More precisely, they want to apply exactly inversion mutations to the cucumber so that the resulting organism could still be turned into the tomato by exactly further inversions.
For dietary reasons, the smaller the resulting BNA is in lexicographic order, the better. So among all BNAs that meet the requirement above, the scientists want the one whose first byteacid has the smallest possible number; in case of a tie, whose second byteacid has the smallest possible number, and so on.
Input
The first line contains three integers , , and (, , ): the length of the cucumber's BNA (equal to the tomato's), the number of inversions needed to turn the cucumber into the tomato, and the fraction to which the resulting organism should be a tomato.
The next two lines each contain integers in the range : the numbers of the successive byteacids of the cucumber's genome and of the tomato's genome, respectively.
You may assume that a sequence of inversions transforming the first BNA into the second exists, and that it is a shortest such sequence.
Output
Output one line with integers: the numbers of the successive byteacids of the BNA of the desired organism.