RT,首先是AC代码
#include<bits/stdc++.h>
using namespace std;
long long ans,sum;
int n,b[100005];
struct node{
int i,v,d;
}a[100005];
int cmp(node x,node y){
if(x.v == y.v )return x.d < y.d ;
return x.v > y.v ;
}
signed main(){
while(cin>>n){
ans=0;
memset(b,0,sizeof(b));
for(int i = 1;i <= n;i++){
scanf("%d%d",&a[i].v,&a[i].d);
}
sort(a+1,a+n+1,cmp);
for(int i = 1;i <= n;i++){
for(int j = a[i].d;j>=1;j--){
if(!b[j]){
ans+=a[i].v;
b[j]=1;
break;
}
}
}
cout<<ans<<endl;
}
return 0;
}
然后,是100%10分代码
#include<bits/stdc++.h>
using namespace std;
long long ans,sum;
int n,b[100005];
struct node{
int i,v,d;
}a[100005];
int cmp(node x,node y){
if(x.v == y.v )return x.d < y.d ;
return x.v > y.v ;
}
signed main(){
while(cin>>n){
ans=0;
memset(b,0,sizeof(b));
for(int i = 1;i <= n;i++){
scanf("%d%d",&a[i].v,&a[i].d);
}
sort(a+1,a+n+1,cmp);
for(int i = 1;i <= n;i++){
if(!b[a[i].d]){
ans+=a[i].v;
b[a[i].d]=1;
continue;
}
for(int j = a[i].d-1;j>=1;j--){
if(!b[j]){
ans+=a[i].v;
b[j]=1;
break;
}
}
}
cout<<ans<<endl;
}
return 0;
}
谢谢各位了