#K91127. Rearrange Array: First Half Ascending, Second Half Descending

    ID: 37907 Type: Default 1000ms 256MiB

Rearrange Array: First Half Ascending, Second Half Descending

Rearrange Array: First Half Ascending, Second Half Descending

Given an array of integers, your task is to rearrange the array such that the first half is sorted in increasing order and the second half is sorted in decreasing order. Specifically, after sorting the entire array in ascending order, the elements in the first ⌊n/2⌋ positions will remain in order, and the remaining elements will be reversed.

In mathematical terms, let \(n\) be the number of elements and \(a_{1}, a_{2}, \dots, a_{n}\) be the sorted sequence. Then the output array should be:

\[ \left[a_{1}, a_{2}, \dots, a_{\lfloor n/2 \rfloor}, a_{n}, a_{n-1}, \dots, a_{\lfloor n/2 \rfloor+1} \right] \]

This problem tests your understanding of sorting, slicing, and array manipulation.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

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

If \(n = 0\), the second line will be empty and the output should be empty as well.

outputFormat

Output the rearranged array to standard output (stdout) as a single line of space-separated integers. There should be no extra spaces at the beginning or end of the output line.

## sample
8
1 2 3 4 5 6 7 8
1 2 3 4 8 7 6 5