#K54107. Two Largest Elements
Two Largest Elements
Two Largest Elements
You are given an array of integers. Your task is to find the two largest elements from the array and print them in descending order (largest first). If the array has fewer than two elements, print nothing.
Details:
- The first line of the input contains a single integer n, representing the number of elements in the array.
- The second line contains n integers separated by spaces.
Output the two largest numbers separated by a space. If there are fewer than two numbers, output an empty line.
Note: The two largest numbers are considered in descending order. In case of duplicate values, they are treated as valid elements.
Mathematically, if we denote the sorted array in descending order as \(a_1 \ge a_2 \ge \cdots \ge a_n\), then output should be \(a_1\) and \(a_2\) when \(n \ge 2\); otherwise, output nothing.
inputFormat
The input is provided via standard input (stdin) in the following format:
- An integer n representing the size of the array.
- n space-separated integers.
If n is less than 2, the output should be empty.
outputFormat
The output should be printed to standard output (stdout). If the array has at least two elements, print the two largest numbers separated by a space in descending order. If the array has fewer than two elements, print nothing.
## sample11
3 1 4 1 5 9 2 6 5 3 5
9 6