From dc8ef4784b6d03a50950f800d5ac098437097071 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 18 Nov 2020 21:36:43 +0800 Subject: [PATCH] =?UTF-8?q?P2073=20=E9=80=81=E8=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R42137379 --- problem/P2073/P2073.cpp | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 problem/P2073/P2073.cpp diff --git a/problem/P2073/P2073.cpp b/problem/P2073/P2073.cpp new file mode 100644 index 00000000..31a0b485 --- /dev/null +++ b/problem/P2073/P2073.cpp @@ -0,0 +1,45 @@ +#include + +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 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::iterator it = a.begin(); it != a.end(); it++) { + ans.c += it->c; + ans.w += it->w; + } + cout << ans.w << ' ' << ans.c << endl; + return 0; +}