From e08a8447265ca284c72241479e215c017074057c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 11 May 2022 21:05:11 +0800 Subject: [PATCH] B - Bracket Score https://atcoder.jp/contests/agc048/submissions/31606165 --- AtCoder/AGC048/B/B.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 AtCoder/AGC048/B/B.cpp diff --git a/AtCoder/AGC048/B/B.cpp b/AtCoder/AGC048/B/B.cpp new file mode 100644 index 00000000..7c575437 --- /dev/null +++ b/AtCoder/AGC048/B/B.cpp @@ -0,0 +1,42 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, a[N], b[N]; +long long ans; +std::priority_queue q1, q2; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + + ans += a[i]; + } + + for (int i = 1; i <= n; i++) { + cin >> b[i]; + + (!(i & 1) ? q1 : q2).push(b[i] - a[i]); + } + + while (!q1.empty()) { + int t = q1.top() + q2.top(); + q1.pop(), q2.pop(); + + if (t <= 0) break; + ans += t; + } + + cout << ans << endl; + + return 0; +}