Ankit_132

C

Aug 7th, 2023
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     _test
  13.     {
  14.         int n;
  15.         cin>>n;
  16.  
  17.         int m = (n*(n-1))/2;
  18.  
  19.         vector<int> a(m);
  20.         for(auto &e: a)
  21.             cin>>e;
  22.  
  23.         sort(a.begin(), a.end());
  24.  
  25.         if(a[0] == a[m-1])
  26.         {
  27.             for(int i=0; i<n; i++)
  28.                 cout<<a[0]<<" ";
  29.             cout<<"\n";
  30.             continue;
  31.         }
  32.  
  33.         map<int, int> cnt;
  34.         for(auto e: a)
  35.             cnt[e]++;
  36.  
  37.         vector<int> ans;
  38.  
  39.         for(auto [x, c]: cnt)
  40.         {
  41.             while(c >= n-(ans.size()+1))
  42.             {
  43.                 c -= n-(ans.size()+1);
  44.                 ans.pb(x);
  45.             }
  46.         }
  47.  
  48.         for(auto e: ans)
  49.             cout<<e<<" ";
  50.         cout<<"\n";
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment