-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
54 lines (46 loc) · 1.01 KB
/
D.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define testcases ll t;cin>>t;while(t--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define dec(x) greater<x>()
template <typename T1, typename T2>
struct less_second
{
typedef pair<T1, T2> type;
bool operator ()(type const& a, type const& b) const
{
return a.second > b.second;
}
};
ll cmp(ll a,ll b){return a>b;}
int main()
{
#ifndef ONLINE_JUDGE
freopen("C:/Users/91731/Documents/input.txt","r",stdin);
freopen("C:/Users/91731/Documents/output.txt","w",stdout);
freopen("C:/Users/91731/Documents/error.txt","w",stderr);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
testcases
{
ll n;
cin>>n;
vector<ll>v(n),f(n+1,0);
for(ll i=0;i<n;i++)
{
cin>>v[i]; f[v[i]]++;
}
sort(f.begin(),f.end());
ll sum = f[n];
for(ll i=n-1;i>=1;i--)
{
if(f[i]>=f[i+1]) f[i]=f[i+1]-1;
if(f[i]>0) sum+=f[i];
}
cout<<sum<<endl;
}
}