@[mxdyzmx](/user/575480) 你忘记判断set是否为空了`大喜`
by forest1145141919810 @ 2023-08-21 17:56:58
@[mxdyzmx](/user/575480) 我用的双set,还挺快的,提交记录第五快,set真好用
```cpp
#include<bits/stdc++.h>
using namespace std;
struct Num{int beauty,cost;};
struct cmp{
bool operator ()(const Num a,const Num b) const{
if(a.cost==b.cost) return a.beauty>b.beauty;
return a.cost<b.cost;
}
};
set<Num,cmp> flower;
set<int> Cost;
int main(){
int opt;scanf("%d",&opt);
while(opt!=-1){
if(opt==1){
Num x;scanf("%d%d",&x.beauty,&x.cost);
if(Cost.count(x.cost)==0)
flower.insert(x),
Cost.insert(x.cost);
}else if(opt==2&&!flower.empty()){
Num maxt=*(--flower.end());
flower.erase(maxt);
Cost.erase(maxt.cost);
}else if(opt==3&&!flower.empty()){
Num mint=*flower.begin();
flower.erase(mint);
Cost.erase(mint.cost);
}
scanf("%d",&opt);
}
long long sum1=0,sum2=0;
for(auto i=flower.begin();i!=flower.end();i++){
Num now=*i;
sum1+=(long long)now.beauty;
sum2+=(long long)now.cost;
}
printf("%lld %lld",sum1,sum2);
return 0;
}
```
by forest1145141919810 @ 2023-08-21 17:58:00
@[mxdyzmx](/user/575480) 有用求关UncleSam_Died
by forest1145141919810 @ 2023-08-21 17:58:36
@[mxdyzmx](/user/575480) N应为1e6
by 幻想繁星 @ 2023-09-06 16:09:55