-
Notifications
You must be signed in to change notification settings - Fork 0
/
prac.cpp
77 lines (67 loc) · 1.3 KB
/
prac.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define repi(a,b) for (int i=a;i<b;i++)
#define repj(a,b) for (int j=a;j<b;j++)
#define repn(a,b) for (int i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define mii map<int,int>
#define ff first
#define ss second
const int N=1e5+5;
void solve()
{
int n;
cin>>n;
vi v(n);
repi(0,n){
cin>>v[i];
}
if (count(all(v),v[0])==n){
cout<<0;
return;
}
unordered_map<int, int> mp;
for (int i=0; i<n; i++) {
if (mp.find(v[i]) != mp.end()) {
mp[v[i]]++;
}
else {
mp[v[i]] = 1;
}
}
int maxi = 0;
for (auto it : mp) {
// cout<<it.ff<<" "<<it.ss<<endl;
maxi = max(maxi, it.ss);
}
int cnt=-1;
for (auto it:mp){
if(it.ss==maxi && it.ss >1){
cnt++;
}
}
if (cnt!=-1){
cout<<(n - maxi+cnt);
}
else{
cout<<(n - maxi);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
cout<<endl;
}
return 0;
}