#K15151. Rearrange and Sort Unique Array
Rearrange and Sort Unique Array
Rearrange and Sort Unique Array
You are given an array of integers which can include negative numbers, positive numbers, and zeros. Your task is to remove duplicate elements from the array, then separate the unique elements into two groups: negative numbers and non-negative numbers. The negative numbers must be sorted in (\textbf{descending order}) and the non-negative numbers in (\textbf{ascending order}).
For example, if the input is 1 -1 2 -2 0
, after removing duplicates, we have ([1, -1, 2, -2, 0]). The negatives, when sorted descending, become ([-1, -2]) and the non-negatives sorted ascending become ([0, 1, 2]).
Note that if one of the groups is empty, you should print an empty line for that group.
inputFormat
Input is read from standard input. The first line contains an integer (n) indicating the number of elements. The second line contains (n) space-separated integers.
outputFormat
Output to standard output in two lines. The first line contains the negative numbers sorted in descending order (separated by a single space). The second line contains the non-negative numbers sorted in ascending order (separated by a single space). If a group is empty, output an empty line for that group.## sample
5
1 -1 2 -2 0
-1 -2
0 1 2
</p>