#C13418. Top Three Largest Distinct Integers

    ID: 42954 Type: Default 1000ms 256MiB

Top Three Largest Distinct Integers

Top Three Largest Distinct Integers

You are given a list of integers. Your task is to find the three largest distinct integers in the list and output them in ascending order. If there are fewer than three distinct integers, output all of them in ascending order.

More formally, let \(A = [a_1, a_2, \dots, a_n]\) be the input list. Define \(D\) as the set of distinct elements in \(A\). If \(|D| \ge 3\), output the three largest elements in \(D\) in increasing order. Otherwise, output all elements of \(D\) in increasing order.

Examples:

  • For the input [4, 1, 7, 3, 7, 8, 1, 4], the distinct numbers are [1, 3, 4, 7, 8] and the three largest distinct numbers in ascending order are [4, 7, 8].
  • For the input [10, 10, 9], the distinct numbers are [9, 10] so the output should be [9, 10].

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains a single integer \(n\), representing the number of elements in the list.
The second line contains \(n\) space-separated integers.

outputFormat

Print the three largest distinct integers (or fewer if there are less than three distinct integers) in ascending order, separated by a single space. The output is to be written to standard output (stdout).

## sample
8
4 1 7 3 7 8 1 4
4 7 8