0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 13:48:48 +00:00
OI-codes/Luogu/problem/P2073/P2073.cpp
2021-01-02 15:30:52 +08:00

46 lines
864 B
C++

#include <bits/stdc++.h>
using namespace std;
struct node {
long long w, c;
node() {
w = 0;
c = 0;
}
node(long long _w, long long _c) {
w = _w;
c = _c;
}
bool operator<(const node a) const {
return c < a.c;
}
};
int main() {
long long op;
node ans;
set<node> a;
while (cin >> op, op != -1) {
if (op == 1) {
long long w, c;
cin >> w >> c;
a.insert(node(w, c));
}
else if (op == 2 && !a.empty()) {
a.erase(--a.end());
}
else if (op == 3 && !a.empty()) {
a.erase(a.begin());
}
}
for (set<node>::iterator it = a.begin(); it != a.end(); it++) {
ans.c += it->c;
ans.w += it->w;
}
cout << ans.w << ' ' << ans.c << endl;
return 0;
}