-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces1183D.cpp
More file actions
56 lines (56 loc) · 888 Bytes
/
Codeforces1183D.cpp
File metadata and controls
56 lines (56 loc) · 888 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define INF 1e9+100
#define pair<int,int> pii
#define ff first
#define ss second
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define FOR(i,n) for(i=0;i<n;i++)
#define REP(i,n) for(i=1;i<=n;i++)
#define pb push_back
main()
{
int n,sum=0,t,i;
int cnt=0,s=0;
cin>>t;
while(t--)
{
cin>>n;
int a[n+3];
for(i=1;i<=n;i++) cin>>a[i];
map<int,int>m;
for(i=1;i<=n;i++)
{
m[a[i]]++;
}
priority_queue<int>q;
for(auto it : m)
{
q.push(it.ss);
}
int cur=q.top();
q.pop();
int sum=cur;
int ans;
while(!q.empty())
{
ans=q.top();
q.pop();
if(ans>=cur)
{
sum+=(cur-1);
cur--;
if(cur==0) break;
}
else
{
sum+=ans;
cur=ans;
}
}
cout<<sum<<endl;
}
}