0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 06:18:48 +00:00

B - Divan and a New Project

https://codeforces.com/contest/1614/submission/137010019
This commit is contained in:
Baoshuo Ren 2021-11-26 20:07:51 +08:00 committed by Baoshuo Ren
parent 5889f1bb0f
commit 0dad6607f2
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

33
CodeForces/1614/B/B.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int t, n, pos[200005];
std::pair<int, int> 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<std::pair<int, int>>());
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;
}