set
#include <set> #include <cstdio> #include <iostream> #define LL long long using namespace std; struct node { LL x, y; node(LL x = 0, LL y = 0) : x(x), y(y) {} inline bool operator < (const node & gg) const { return y < gg.y; } }; LL ans1, ans2; set <node> s; set <node> :: iterator it; inline int read() { int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1; for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } int main() { int x, y, z; while(1) { z = read(); if(z == -1) break; if(z == 1) { x = read(); y = read(); if(s.find(node(x, y)) != s.end()) continue; ans1 += x; ans2 += y; s.insert(node(x, y)); } if(z == 3) { if(!s.size()) continue; it = s.begin(); ans1 -= (*it).x; ans2 -= (*it).y; s.erase(it); } if(z == 2) { if(!s.size()) continue; it = s.end(); it--; ans1 -= (*it).x; ans2 -= (*it).y; s.erase(it); } } printf("%lld %lld ", ans1, ans2); return 0; }