TLE,求条
查看原帖
TLE,求条
1046226
Xuguangyuan楼主2025/7/28 21:20
#include<bits/stdc++.h>
using namespace std;
const long int N=1e5+1;
long long n,ans;
bool op[N];
struct node {
long long d,p;
}s[N];
bool cmp(node a,node b )
{
return a.p>b.p;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i].d>>s[i].p;
}
sort(1+s,1+s+n,cmp);
for(int i=1;i<=n;i++)
{
if(s[i].d>=N) ans+=s[i].p;
else {
for(int j=s[i].d;j>=1;j--){
if(op[j]==0) {op[j]=1;ans+=s[i].p; break;}
}
}

}

cout<<ans;
return 0;
}

2025/7/28 21:20
加载中...