时间复杂度$O(nlogn)$
#include<iostream>
#include<algorithm>
#include<cstring>
#define endl '\n';
//多开几个,wa了一次
const int N = 1e5+10;
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
//一个pair
PII w[N];
int n;
//哈希表
int hs[10];
int main()
{
//取消同步流
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//读入n
cin >> n;
//读入每个数和代价
for(int i=1;i<=n;i++){
cin >> w[i].first >> w[i].second;
}
//排序,从下标1开始
sort(w+1,w+1+n);
LL res = 0;
//计算每个数出现的次数
for(int i=1;i<=n;i++){
hs[w[i].first]+=1;
}
//每个数应该出现的次数
int cnt = n/10;
//统计代价
for(int i=1;i<=n;i++){
if(hs[w[i].first]>cnt){
res += w[i].second;
hs[w[i].first]-=1;
}
}
//输出答案
cout << res << endl;
return 0;
}