Mock CCC '21 S3 - Lexicographically Smallest Permutation Subsequence

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 0.1s
Java 0.25s
Python 3 0.5s
Memory limit: 1G

Problem type

Given a list of N positive integers, none larger than K, compute the lexicographically smallest permutation of the first K positive integers that is a subsequence of the list.


1 \le K \le N \le 2 \cdot 10^5

Each integer from 1 to K appears at least once in the list.

Input Specification

The first line contains two space-separated integers N and K. Each of the next N lines each contains a single integer, the integers of the list in order.

Output Specification

Output K space-separated integers, the lexicographically smallest permutation that is a subsequence.

Sample Input

6 3

Sample Output

2 1 3


  • 0
    zhenga1  commented on Feb. 16, 2021, 1:23 a.m.

    I'm stuck getting wrong answer on Testcase 3.

  • 1
    zhenga1  commented on Feb. 15, 2021, 2:45 a.m.

    Can I ask why I am getting presentation error?

    • 1
      Aaeria  commented on Feb. 16, 2021, 11:24 a.m.

      you have to remove trailing spaces and end with a newline