Genetic engineering
Time limit1sMemory limit128 MB
Delete the fewest elements so the rest splits into blocks of k equal values, and print the lexicographically smallest among the longest such genomes.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Segment tree
- Solved
- No attempts yet
Problem
Byteotian paleoarchaeologists recently dug up a few lumps of amber with ancient mosquitoes trapped inside. Analysis of the samples showed the insects came from the Jurassic period, so they had most likely fed on the large reptiles that ruled the Byteotian lands. That gave the geneticists an idea: recover byteoraptor genetic material from the blood inside a mosquito.
Like every Byteotian organism, a byteoraptor genome is a chain of byteo-aminoacids. For simplicity the types of byteo-aminoacids are numbered with natural numbers. A genome carries redundancy. Every type is repeated times, so the length of a correct genome is always a multiple of . In other words, split a genome from the front into blocks of consecutive byteo-aminoacids and each block holds a single type.
The geneticists isolated a chain of byteo-aminoacids from the blood of one mosquito. The chain may not be a valid genome, because they suspect foreign byteo-aminoacids contaminated it. They now want to delete as few byteo-aminoacids as possible so that a normal genome remains. The byteo-aminoacids that survive keep their original order. When several answers have the same length, they look for the genome that comes first in lexicographical order.
Two chains and of the same length are compared like this. Find the first position where they differ, and the chain whose byteo-aminoacid carries the smaller number at that position comes first.
Input
The first line has the length of the extracted chain and the redundancy degree of a correct genome (, ).
The second line has the types of the byteo-aminoacids along the chain, in order ().
Output
On the first line print the greatest length of a correct genome that can be made by deleting byteo-aminoacids from the chain ().
On the second line print the types of that genome in order, separated by single spaces. When several answers of length exist, print the one that comes first in lexicographical order. If , that is, if no non-empty correct genome can be made at all, leave the second line empty.