Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int int64_t
- using namespace std;
- int32_t main()
- {
- int t;
- cin >> t;
- while (t--)
- {
- int n;
- cin >> n;
- int a [n];
- for (auto &i: a)
- cin >> i;
- if (n == 1)
- {
- cout << "0\n";
- continue;
- }
- map <int, int> cnt;
- for (auto i: a)
- cnt [i]++;
- int ans = LLONG_MIN;
- for (auto i: cnt)
- {
- int now;
- if (i.second > cnt.size())
- now = cnt.size();
- else
- now = min(i.second, (int)cnt.size() - 1);
- ans = max(now, ans);
- }
- cout << ans << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment