-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINCRDEC.cpp
67 lines (60 loc) · 1.17 KB
/
INCRDEC.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
65
66
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define lli long long int
#define vi vector<int>
#define vll vector<lli>
#define pb push_back
#define all(v) v.begin(),v.end()
void solve(){
int n,i;
cin >> n;
vi arr(n),left,right;
int freq[200005] = {0};
rep(i,n){
cin >> arr[i];
freq[arr[i]]++;
}
sort(all(arr));
if(freq[arr[n-1]] > 1){
cout << "NO" << endl;
return;
}
rep(i,n-1){
if(freq[arr[i]] > 2){
cout << "NO" << endl;
return;
}
}
cout << "YES\n";
left.pb(arr[0]);
f(i,1,n){
if(left[(int)left.size()-1] < arr[i]){
left.pb(arr[i]);
}else{
right.pb(arr[i]);
}
}
//cout << left.size() << " " << right.size() << endl;
f(i,0,(int)left.size()){
cout << left[i] << " ";
}
fd(i,(int)right.size()-1,0){
cout << right[i] << " ";
}
cout << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test_cases;
//test_cases = 1;
cin >> test_cases;
while(test_cases--){
solve();
}
return 0;
}