Codeforces 1335C - Two Teams Composing Solution

  1. Solution in C++:
  2. ///**********ALLAH IS ALMIGHTY************///
  3. ///AH Tonmoy
  4. ///Department of CSE,23rd batch
  5. ///Islamic University,Bangladesh
  6. #include<iostream>
  7. #include <algorithm>
  8. #include <map>
  9. using namespace std;
  10. int main()
  11. {
  12. int t,n,i,j,a,mx,f,mr,ms,r;
  13. cin>>t;
  14. while(t--)
  15. {
  16. mr=0,ms=0;
  17. map<int,int>m;
  18. cin>>n;
  19. for(i=0; i<n; i++)
  20. {
  21. cin>>a;
  22. m[a]++;
  23. mr=max(mr,m[a]);
  24. }
  25.  
  26. ms=m.size();
  27. r=max(min(ms,mr-1),min(mr,ms-1));
  28. cout<<r<<endl;
  29. r=0;
  30. }
  31. }

No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.