#K8081. Custom Sorting with Negative Numbers

    ID: 35613 Type: Default 1000ms 256MiB

Custom Sorting with Negative Numbers

Custom Sorting with Negative Numbers

Given a list of integers, your task is to sort them with a twist: sort all non-negative numbers in ascending order and move all the negative numbers to the end in descending order.

Mathematically, if the input array is \(A\), then the output array \(B\) is given by:

\[ B = \Big( \text{sort}(\{ x \in A : x \ge 0 \}) \Big) \Vert \Big( \text{sort}_{\text{desc}}(\{ x \in A : x < 0 \}) \Big) \]

where \(\Vert\) indicates the concatenation of two lists.

inputFormat

The input is given from standard input (stdin). The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.

outputFormat

Print the sorted list to standard output (stdout). The non-negative numbers appear first in ascending order, followed by the negative numbers in descending order. The numbers should be separated by a single space.

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