ProgMe

Untitled

Apr 13th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int int64_t
  3.  
  4. using namespace std;
  5.  
  6. int32_t main()
  7. {
  8. int t;
  9. cin >> t;
  10. while (t--)
  11. {
  12. int n;
  13. cin >> n;
  14. int a [n];
  15. for (auto &i: a)
  16. cin >> i;
  17. if (n == 1)
  18. {
  19. cout << "0\n";
  20. continue;
  21. }
  22. map <int, int> cnt;
  23. for (auto i: a)
  24. cnt [i]++;
  25. int ans = LLONG_MIN;
  26. for (auto i: cnt)
  27. {
  28. int now;
  29. if (i.second > cnt.size())
  30. now = cnt.size();
  31. else
  32. now = min(i.second, (int)cnt.size() - 1);
  33. ans = max(now, ans);
  34. }
  35. cout << ans << "\n";
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment