记录编号 601845 评测结果 AAAAAAAAAA
题目名称 3097.[POJ 1456]超市 最终得分 100
用户昵称 Gravatar秋_Water 是否通过 通过
代码语言 C++ 运行时间 0.843 s
提交时间 2025-06-29 09:12:07 内存使用 3.76 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=25010;
struct cow{
    int p,d;
}a[N];
bool cmp(cow a,cow b){
    return a.p>b.p;
}
bool bj[N];
int n,m,ans,maxx;
int main(){
    while(cin>>n){
        ans=0;
        memset(bj,0,sizeof(bj));
        for(int i=1;i<=n;i++){
            cin>>a[i].p>>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(bj[j]==0){
                    bj[j]=1;
                    ans+=a[i].p;
                    break;
                }
            }
        }
        cout<<ans<<"\n";   
    }
	
    
    return 0;
}