cswork / OA打开练习工作台

IBMOA #53

Meandering Array

估计简单可在线判题

考点(AI 标注)原地数组双指针滑窗

Output all array elements in the order largest, smallest, second largest, second smallest, and so on, keeping duplicates and using each input element exactly once.

输入格式

The first line contains n, and the second line contains the array. 2≤n≤100000, −10^6≤element≤10^6, and duplicates are allowed.

输出格式

Output n elements arranged in alternating maximum-minimum order.

样例 1

输入:

5
-1 1 2 3 -5

输出:

3 -5 2 -1 1

样例 2

输入:

3
2 2 1

输出:

2 1 2

样例 3

输入:

2
0 0

输出:

0 0

样例说明

The examples give 3 -5 2 -1 1; 2 1 2; and 0 0 respectively.