萌新 set 求助!(不用看超时,就是想知道为神马 RE)
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
const int MAXN=100010;
typedef long long ll;
int type,n;
typedef pair<ll,ll> P;
struct node
{
ll value,price;
bool operator <(const node&a) const
{
return a.price>price;
}
};
set<node>st;
node make(ll value,ll price){node ans;ans.price=price,ans.value=value;return ans;}
void sum()
{
node ans;
ans.value=ans.price=0;
for(register set<node>::iterator it=st.begin();it!=st.end();it++)
{
node a=*it;
ans.value+=a.value,ans.price+=a.price;
}
printf("%lld %lld\n",ans.value,ans.price);
exit(0);
}
void print()
{
for(register set<node>::iterator it=st.begin();it!=st.end();it++)
{
node a=*it;
printf("%lld %lld\n",a.value,a.price);
}
}
void pre()
{
while(true)
{
scanf("%d",&type);
if(type==-1)
{
if(st.size()==0) continue;
else sum();
}
else
{
if(type==1)
{
ll v,p;
scanf("%lld%lld",&v,&p);
st.insert(make(v,p));
}
else
{
if(type==3) st.erase(st.begin());
else st.erase(--st.end());
}
}
}
}
int main()
{
pre();
}