시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 512 MB | 110 | 40 | 36 | 45.000% |
You are given a sequence of n integers X = [x1, x2, ..., xn] and an integer k. It is guaranteed that 1 ≤ xi ≤ k, and every integer from 1 to k appears in the list X at least once.
Find the lexicographically smallest subsequence of X that contains each integer from 1 to k exactly once.
The first line of input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ∙ 105), where n is the size of the sequence, and the sequence consists only of integers from 1 to k.
Each of the next n lines contains a single integer xi (1 ≤ xi ≤ k). These are the values of the sequence X in order. It is guaranteed that every value from 1 to k will appear at least once in the sequence X.
Output a sequence of integers on a single line, separated by spaces. This is the lexicographically smallest subsequence of X that contains every value from 1 to k.
6 3 3 2 1 3 1 3
2 1 3
10 5 5 4 3 2 1 4 1 1 5 5
3 2 1 4 5