Advertisement
Guest User

Untitled

a guest
May 25th, 2022
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. int32_t main()
  2. {
  3. fastio;
  4. int t;
  5. cin>>t;
  6. while(t--)
  7. {
  8. int n;
  9. cin>>n;
  10. vector<int> arr(n);
  11. input(arr);
  12. sort(arr.begin(), arr.end());
  13. int j = 0;
  14. vector<int> temp(n);
  15. for(int i=0; i<n; i+=2){
  16. temp[i] = arr[j++];
  17. }
  18. for(int i=1; i<n; i+=2){
  19. temp[i] = arr[j++];
  20. }
  21. bool possible = true;
  22. for(int i=0; i<n; i++)
  23. {
  24. int left = temp[(i == 0 ? n-1 : i-1)];
  25. int right = temp[(i == n-1 ? 0 : i+1)];
  26. if(temp[i] < left && temp[i] < right)
  27. {
  28.  
  29. }
  30. else if(temp[i] > left && temp[i] > right)
  31. {
  32.  
  33. }
  34. else
  35. possible = false;
  36. }
  37. if(possible){
  38. cout<<"YES"<<endl;
  39. print(temp);
  40. }
  41. else
  42. cout<<"NO"<<endl;
  43. }
  44. return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement