mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:11:59 +00:00
B - Divan and a New Project
https://codeforces.com/contest/1614/submission/137010019
This commit is contained in:
parent
5889f1bb0f
commit
0dad6607f2
33
CodeForces/1614/B/B.cpp
Normal file
33
CodeForces/1614/B/B.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user