-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
64 lines (62 loc) · 1.31 KB
/
C.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
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[100005],b[100005];
int main()
{
fastio;
long long t,n,i,p;
cin>>t;
while(t--)
{
cin>>n;
p=0;
for(i=0;i<n;i++)
{
cin>>ara[i];
b[i]=ara[i];
}
sort(b,b+n);
for(i=0;i<n;i++)
{
if(i%2==0)
ara[i]=b[i/2];
else
ara[i]=b[n/2+n%2+i/2];
}
ara[n]=ara[0];
for(i=0;i<n;i++)
{
//cout<<i<<"\n";
if(i==0)
{
if(ara[i]>=ara[n-1] || ara[i]>=ara[i+1])
{
p=1;
break;
}
}
else if(i%2==0 && (ara[i]>=ara[i-1] || ara[i]>=ara[i+1]))
{
p=1;
break;
}
else if(i%2==1 && (ara[i]<=ara[i-1] || ara[i]<=ara[i+1]))
{
p=1;
break;
}
}
if(p==0)
{
cout<<"YES"<<"\n";
for(i=0; i<n; i++)
cout<<ara[i]<<" ";
cout<<"\n";
continue;
}
else
cout<<"NO"<<"\n";
}
return 0;
}