Advertisement
TAHMID37

B

Jun 27th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define pi acos(-1.0)
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  10. #define ll long long
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. #define in insert
  15. #define mp make_pair
  16. #define GCD(a,b) __gcd(a,b);
  17. #define endl "\n"
  18. #define FRU freopen("out.txt","w",stdout)
  19. #define FRO freopen("in.txt","r",stdin)
  20. #define INFLL 9223372036854775807
  21. #define debug 0
  22. #define MAXN   100001
  23. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  24. int main()
  25. {
  26.     fastio;
  27.     ll t;
  28.     cin>>t;
  29.     while(t--)
  30.     {
  31.         ll n,i,maxe=0,f=1;
  32.         cin>>n;
  33.         vector<ll>v(n),extra;
  34.         set<ll>s;
  35.         for(i=0;i<n;i++)
  36.         {
  37.             cin>>v[i];
  38.             s.in(v[i]);
  39.             if(v[i]>maxe)
  40.             {
  41.                 maxe=v[i];
  42.             }
  43.         }
  44.         sort(v.begin(),v.end());
  45.         vector<ll>ff(s.begin(),s.end());
  46.         ll y=count(v.begin(),v.end(),maxe);
  47.         if(y!=1)
  48.         {
  49.             f=0;
  50.         }
  51.         for(i=0;i<s.size();i++)
  52.         {
  53.             if(f==0)
  54.                 break;
  55.             ll x;
  56.             x=count(v.begin(),v.end(),ff[i]);
  57.             if(x==2)
  58.             {
  59.                 extra.pb(ff[i]);
  60.             }
  61.             if(x>=3)
  62.             {
  63.                 f=0;
  64.               break;
  65.             }
  66.         }
  67.         if(f)
  68.         {
  69.             cout<<"YES"<<endl;
  70.             for(auto d:s)
  71.             {
  72.                 cout<<d<<" ";
  73.             }
  74.             sort(extra.rbegin(),extra.rend());
  75.             if(extra.size()!=0)
  76.             {
  77.                 for(auto e:extra)
  78.                 {
  79.                     cout<<e<<" ";
  80.                 }
  81.             }
  82.             cout<<endl;
  83.         }
  84.         else
  85.             cout<<"NO"<<endl;
  86.  
  87.  
  88.              s.clear();
  89.              extra.clear();
  90.              ff.clear();
  91.  
  92.         if(debug)
  93.         {
  94.             cout<<maxe<<" "<<y<<" "<<f<<endl;
  95.             for(auto z:s)
  96.             {
  97.                 cout<<z<<" ";
  98.             }
  99.             cout<<endl;
  100.             for(auto d:extra)
  101.             {
  102.                 cout<<d<<" ";
  103.             }
  104.             cout<<endl;
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement