rt
下面的是50分代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct Schedule{
int t,v;
}a[maxn];
int n,t;
long long ans;
bool cmp(Schedule a,Schedule b){
return a.t<b.t;
}
priority_queue<int,vector<int>,greater<int> > q;
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].t>>a[i].v;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
if(a[i].t<=q.size()&&a[i].v>q.top()) {
q.pop();
q.push(a[i].v);
}
else {
q.push(a[i].v);
}
}
while(!q.empty())
{
ans+=q.top();
q.pop();
}
cout<<ans<<endl;
return 0;
}
把
if(a[i].t<=q.size()&&a[i].v>q.top())
换成
if(a[i].t<=q.size()) {
if(a[i].v>q.top())
就对了,这是为什么