fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int n,x;
  11. cin>>n;
  12. map<int,int,greater<int> >m;
  13. for(int i=0;i<n;i++)
  14. {
  15. cin>>x;
  16. m[x]++;
  17. }
  18. map<int,int,greater<int> >::iterator it;
  19. int sum=0;
  20. int g=0,s=0,b=0;
  21. for(it=m.begin();it!=m.end();it++)
  22. {
  23. sum+=(*it).second;
  24. if(sum>n/2)break;
  25. if(g==0)g=(*it).second;
  26. else if(s<=g)s+=(*it).second;
  27. else if(b==0)b=(*it).second;
  28. //else if(s<=g)s+=(*it).second;
  29. else b+=(*it).second;
  30. }
  31. if(g<s && g<b && g!=0 && s!=0 && b!=0 && (g+s+b<=n/2))cout<<g<<" "<<s<<" "<<b<<endl;
  32. else cout<<"0 0 0 "<<endl;
  33. m.clear();
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 4516KB
stdin
5
12
5 4 4 3 2 2 1 1 1 1 1 1
4
4 3 2 1
1
1000000
20
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
32
64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11
stdout
1 2 3
0 0 0 
0 0 0 
1 2 7
2 6 6