STL set求调
  • 板块P2073 送花
  • 楼主mxdyzmx
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/8/14 16:53
  • 上次更新2023/11/3 03:50:48
查看原帖
STL set求调
575480
mxdyzmx楼主2023/8/14 16:53

rt,RE20pts

#include <bits/stdc++.h>
using u64=long long;
using namespace std;
const int N=1e5+10;
set<u64> s;
u64 cost[N];
u64 t,w,c,wst=0,ans=0;
int main(){
	while(true){
		scanf("%lld",&t);
		if(t==1){
			scanf("%lld%lld",&w,&c);
			if(s.count(c)) continue;
			s.insert(c);
			cost[c]=w;
		}
		if(t==2) if(s.size()!=0) s.erase(--s.end());
		if(t==3) if(s.size()!=0) s.erase(s.begin());
		if(t==-1) break;
	}
	set<u64>::iterator it;
	for(it=s.begin();it!=s.end();it++){
		ans += cost[*it];
		wst += *it;
	}
	printf("%lld %lld",ans,wst);
	return 0;
}
2023/8/14 16:53
加载中...