1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <iostream> #include <cstdio> #include <map> using namespace std; typedef long long LL; map <LL, LL> mp; int main() { while (true) { int op; cin >> op; if (op == -1) break; else if (op == 1) { int a, b; cin >> a >> b; if (mp.count(b)) continue; mp.insert(make_pair(b, a)); } else if (op == 2 && !mp.empty()) mp.erase(--mp.end()); else if (op == 3 && !mp.empty()) mp.erase(mp.begin()); } int res1 = 0, res2 = 0; for (map<LL, LL>:: iterator it = mp.begin(); it != mp.end(); it++) res1 += (*it).second, res2 += (*it).first; cout << res1 << ' ' << res2; return 0; }
|