#C12910. First K Largest Unique Elements

    ID: 42390 Type: Default 1000ms 256MiB

First K Largest Unique Elements

First K Largest Unique Elements

Given a list of integers and an integer \(k\), the task is to find the first \(k\) largest unique elements from the list. The list may contain duplicate values, but only unique numbers should be considered. The output must display the selected unique numbers in descending order.

For example, if the list is [4, 1, 2, 2, 3, 4, 5] and \(k = 3\), the answer should be [5, 4, 3].

inputFormat

The input is read from standard input (stdin) and consists of three parts:

  • The first line contains an integer \(n\) representing the number of elements in the list.
  • The second line contains \(n\) space-separated integers.
  • The third line contains an integer \(k\), indicating the number of largest unique elements to output.

outputFormat

Print the first \(k\) largest unique elements in descending order on a single line, separated by a single space. If there are fewer than \(k\) unique elements, print all the unique elements.

## sample
7
4 1 2 2 3 4 5
3
5 4 3