34分求调:
#include <bits/stdc++.h>
#pragma GCC optimeze(2)
#define int long long
#define Set SetConsoleOutputCP(65001);
using namespace std;
int n;
struct Node{
int d;
int p;
}work[100010];
int cmp(Node a,Node b){
return a.p>b.p;
}
int k[100001];
int ans=0;
int find(int x){
for(int i=1;i<=k[0];i++){
if(k[i]==x)return 1;
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>work[i].d>>work[i].p;
}
sort(work+1,work+n+1,cmp);
for(int i=1;i<=n;i++){
int flag=0;
while(find(work[i].d)){
if(work[i].d==1){
flag=1;
break;
}
work[i].d--;
}
if(flag==1)continue;
k[k[0]++]=work[i].d;
ans+=work[i].p;
}
cout<<ans;
return 0;
}