아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Sorted Adjacent Differences

시간 제한1초메모리 제한1024 MB

요약
주어진 배열을 재배열해 인접한 원소 사이 절댓값 차이가 감소하지 않도록 만든다. 조건을 만족하는 배열은 아무거나 출력해도 된다.
난이도

보통10점 중 5점

유형
정렬, 그리디, 투 포인터, 수학
정답자
아직 제출이 없습니다

문제

You have array of nn numbers a_1,a_2,…,a_na\_{1}, a\_{2}, \ldots, a\_{n}.

Rearrange these numbers to satisfy ∣a_1−a_2∣≤∣a_2−a_3∣≤…≤∣a_n−1−a_n∣|a\_{1} - a\_{2}| \le |a\_{2} - a\_{3}| \le \ldots \le |a\_{n-1} - a\_{n}|, where ∣x∣|x| denotes absolute value of xx. It's always possible to find such rearrangement.

Note that all numbers in aa are not necessarily different. In other words, some numbers of aa may be same.

You have to answer independent tt test cases.

입력

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^{4}) --- the number of test cases.

The first line of each test case contains single integer nn (3≤n≤1053 \le n \le 10^{5}) --- the length of array aa. It is guaranteed that the sum of values of nn over all test cases in the input does not exceed 10510^{5}.

The second line of each test case contains nn integers a_1,a_2,…,a_na\_{1}, a\_{2}, \ldots, a\_{n} (−109≤a_i≤109-10^{9} \le a\_{i} \le 10^{9}).

출력

For each test case, print the rearranged version of array aa which satisfies given condition. If there are multiple valid rearrangements, print any of them.

힌트

In the first test case, after given rearrangement, ∣a_1−a_2∣=0≤∣a_2−a_3∣=1≤∣a_3−a_4∣=2≤∣a_4−a_5∣=2≤∣a_5−a_6∣=10|a\_{1} - a\_{2}| = 0 \le |a\_{2} - a\_{3}| = 1 \le |a\_{3} - a\_{4}| = 2 \le |a\_{4} - a\_{5}| = 2 \le |a\_{5} - a\_{6}| = 10. There are other possible answers like "5 4 5 6 -2 8".

In the second test case, after given rearrangement, ∣a_1−a_2∣=1≤∣a_2−a_3∣=2≤∣a_3−a_4∣=4|a\_{1} - a\_{2}| = 1 \le |a\_{2} - a\_{3}| = 2 \le |a\_{3} - a\_{4}| = 4. There are other possible answers like "2 4 8 1".

예제1

  1. 예제 1

    입력
    2
    6
    5 -2 4 8 6 5
    4
    8 1 4 2
    
    예상 출력
    5 5 4 6 8 -2
    1 2 4 8