-
Notifications
You must be signed in to change notification settings - Fork 8
/
1335C_TwoTeamsComposing.cpp
45 lines (36 loc) · 1.03 KB
/
1335C_TwoTeamsComposing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
~ Author : @tridib_2003
~ Title : 1335C. Two Teams Composing
~ Link : https://codeforces.com/contest/1335/problem/C
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
vector<int> a(n);
map<int, int> mp;
for (int i = 0; i < n; ++i) {
cin >> a[i];
++mp[a[i]]; // Increasing the freq by 1
}
// Finding the one with max freq
int max_freq = 0;
map<int, int>::iterator itr;
for (itr = mp.begin(); itr != mp.end(); ++itr)
max_freq = max(itr->second, max_freq);
// Finding number of players in a team
int players = 0;
for (int c = 1; c <= max_freq; ++c) {
if (max_freq == c ? c <= (mp.size() - 1) : max_freq > c && c <= mp.size())
players = c;
}
cout << players << '\n';
}
return 0;
}