蒟蒻 - 题目 - Daimayuan Online Judge
map可以一一映射,按键值从小到大排序
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
map<int,int>mp1;
map<int,int>mp2;
int main()
{
int n;
cin>>n;
while(n--){
int op;
cin>>op;
if(op==1){
int w,t;
cin>>w>>t;
if(mp1.count(w)==0&&mp2.count(t)==0){
mp1[w]=t;
mp2[t]=w;
}
}
else if(op==2){
mp2.erase(mp1.begin()->second);
mp1.erase(mp1.begin());
}
else{
mp1.erase(mp2.begin()->second);
mp2.erase(mp2.begin());
}
}
int res=0;
for(auto v:mp1){
res+=v.first;
}
cout<<res<<endl;
return 0;
}