#K13486. Find the Largest Unique Elements

    ID: 23923 Type: Default 1000ms 256MiB

Find the Largest Unique Elements

Find the Largest Unique Elements

You are given an array of integers and an integer \(n\). Your task is to find the \(n\) largest unique elements in the array and output them in descending order. If the number of unique elements in the array is less than \(n\), output all the unique elements in descending order.

The problem can be formalized as follows. Let \(A\) be the input array and \(U = \{ a : a \in A \}\) be the set of unique elements of \(A\). Sort \(U\) in descending order to obtain \(U' = [u_1, u_2, \dots, u_k]\) such that \(u_1 \ge u_2 \ge \cdots \ge u_k\). Then, output the first \(\min(n, k)\) elements of \(U'\).

If \(n \le 0\) or the array is empty, output an empty result.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  1. The first line contains a sequence of integers separated by spaces. This represents the array. It can be empty.
  2. The second line contains a single integer \(n\), which specifies the number of largest unique elements to retrieve.

outputFormat

Output the resulting unique elements in descending order on a single line, separated by a single space. If there are no elements to output, print an empty line.

## sample
4 5 6 3 2 7
3
7 6 5