Wave Arrangement
Rearrange into a wave: a1 ≥ a2 ≤ a3 ≥ a4 ... Print the lexicographically SMALLEST such arrangement.
Input: the first line has N; the second line has N integers.
Output: the wave-ordered values.
Constraints:
- 1 ≤ N ≤ 105
- -10000 ≤ ai ≤ 10000
Sample Tests
Input 1
5 3 6 5 10 7
Output 1
5 3 7 6 10
Input 2
2 1 2
Output 2
2 1
Discussion (opens after you solve — no spoilers before)
No comments yet.