#K33642. Custom Even-Odd Sort
Custom Even-Odd Sort
Custom Even-Odd Sort
You are given an array of integers. Your task is to arrange the array in such a way that all the even numbers appear first in ascending order, followed by all the odd numbers in descending order.
In other words, if we denote the even numbers by \(E\) and odd numbers by \(O\), then the final sorted list should satisfy:
[ E_{1} \leq E_{2} \leq \cdots \leq E_{k} \quad \text{and} \quad O_{1} \geq O_{2} \geq \cdots \geq O_{m} ]
and the output is the concatenation of the sorted even numbers followed by the sorted odd numbers.
Note: The input format is designed for a single test case where the first integer represents the number of elements in the array, followed by the elements of the array.
inputFormat
The first line of input contains an integer \(n\), the number of elements in the array. The second line contains \(n\) space-separated integers.
outputFormat
Output a single line containing the sorted array, where even numbers (sorted in ascending order) appear first and odd numbers (sorted in descending order) follow. The numbers should be separated by a single space.
## sample6
5 3 2 8 1 4
2 4 8 5 3 1