Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int32_t main()
- {
- fastio;
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- vector<int> arr(n);
- input(arr);
- sort(arr.begin(), arr.end());
- int j = 0;
- vector<int> temp(n);
- for(int i=0; i<n; i+=2){
- temp[i] = arr[j++];
- }
- for(int i=1; i<n; i+=2){
- temp[i] = arr[j++];
- }
- bool possible = true;
- for(int i=0; i<n; i++)
- {
- int left = temp[(i == 0 ? n-1 : i-1)];
- int right = temp[(i == n-1 ? 0 : i+1)];
- if(temp[i] < left && temp[i] < right)
- {
- }
- else if(temp[i] > left && temp[i] > right)
- {
- }
- else
- possible = false;
- }
- if(possible){
- cout<<"YES"<<endl;
- print(temp);
- }
- else
- cout<<"NO"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement