#P1716. Double Alternating Sequence
Double Alternating Sequence
Double Alternating Sequence
You are given n integers where \(n \le 1000\) and each integer is in the range \(-2147483648\) to \(2147483647\). You need to arrange these numbers into a Double Alternating Sequence following the rule:
- The first element is the maximum number.
- The second element is the minimum number.
- The third element is the second maximum number.
- The fourth element is the second minimum number.
- And so on until all numbers have been used.
For example, if the numbers are [1, 2, 3, 4], then the resulting sequence should be [4, 1, 3, 2].
inputFormat
The first line of input contains a single integer \(n\) (the number of integers). The second line contains \(n\) space-separated integers.
outputFormat
Output a single line containing the rearranged sequence according to the double alternating sequence rule. The numbers should be separated by a single space.
sample
4
1 2 3 4
4 1 3 2