From 0dad6607f226b462abf0f0433b822cdd258c1513 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 26 Nov 2021 20:07:51 +0800 Subject: [PATCH] B - Divan and a New Project https://codeforces.com/contest/1614/submission/137010019 --- CodeForces/1614/B/B.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CodeForces/1614/B/B.cpp diff --git a/CodeForces/1614/B/B.cpp b/CodeForces/1614/B/B.cpp new file mode 100644 index 00000000..f9c9cd8a --- /dev/null +++ b/CodeForces/1614/B/B.cpp @@ -0,0 +1,33 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +int t, n, pos[200005]; +std::pair a[200005]; + +int main() { + cin >> t; + while (t--) { + long long ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i].first; + a[i].second = i; + } + std::sort(a + 1, a + 1 + n, std::greater>()); + for (int i = 1, j = 1, f = 1; i <= n; i++) { + pos[a[i].second] = j * f; + ans += j * 2ll * a[i].first; + if (f == -1) j++; + f = -f; + } + cout << ans << endl; + for (int i = 0; i <= n; i++) { + cout << pos[i] << ' '; + } + cout << endl; + } + return 0; +}