-
Notifications
You must be signed in to change notification settings - Fork 0
/
REARR5.cpp
53 lines (52 loc) · 900 Bytes
/
REARR5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<stdio.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
const int N=1e7+3;
void qso(int a[],int l,int r)
{
int m=a[(l+r)/2],i=l,j=r;
while(i<=j)
{
while(a[i]<m) i++;
while(a[j]>m) j--;
if(i<=j)
{
int t=a[i];
a[i]=a[j];
a[j]=t;
i++;j--;
}
}
if(i<r) qso(a,i,r);
if(l<j) qso(a,l,j);
}
void xuly()
{
int n;
scanf("%d",&n);
int a[n+4],m;
f0(i,n) scanf("%d",&a[i]);
qso(a,0,n-1);
if(n%2==0)
{
for(int i=0;i<n/2;i++) printf("%d %d ",a[n-i-1],a[i]);
}
else
{
for(int i=0;i<(n-1)/2;i++) printf("%d %d ",a[n-i-1],a[i]);
printf("%d",a[n/2]);
}
printf("\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--) xuly();
return 0;
}