Problems > Wave Arrangement

Wave Arrangement

Difficulty: 1300 3500 ms 128 MB

sorting

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.