// 方案一#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<unordered_set>#include<math.h>#defineendl'\n'#definefifirst#definesesecondusingnamespace std;using ll =longlong;voidsolve(){int n; cin >> n;vector<int>a(n +1);vector<int>p(n +1);for(int i =1; i <= n; i ++) cin >> a[i], p[i]= i;sort(p.begin()+1, p.end(),[&](int x,int y){return a[x]> a[y];// a[p[i]] > a[p[j]]});vector<int>res(n +1);res[0]=0;for(int i =1; i <= n; i +=2) res[p[i]]=(i +1)/2;for(int i =2; i <= n; i +=2) res[p[i]]=-(i +1)/2;ll sum =0;for(int i =1; i <= n; i ++) sum +=2ll* a[i]*abs(res[i]);cout << sum << endl;for(int i =0; i <= n; i ++) cout << res[i]<<" \n"[i == n];}intmain(){cin.tie(nullptr)->sync_with_stdio(false);int _;cin >> _;while(_ --)solve();return0;}// 方案二#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<unordered_set>#defineendl'\n'#definefifirst#definesesecondusingnamespace std;using ll =longlong;constint N =2e5+10;typedef pair<int,int> PII;PII a[N];int p[N];voidsolve(){int n; cin >> n;for(int i =1; i <= n; i ++) cin >> a[i].fi, a[i].se = i;sort(a +1, a + n +1, greater<PII>());p[0]=0;int l =-1, r =1;ll sum =0;for(int i =1; i <= n; i ++){if(i %2){sum +=2ll* a[i].fi * r;p[a[i].se]= r ++;}else{sum +=2ll* a[i].fi *(-l);p[a[i].se]=(l --);}}cout << sum << endl;for(int i =0; i <= n; i ++) cout << p[i]<<" \n"[i == n];}intmain(){cin.tie(nullptr)->sync_with_stdio(false);int _;cin >> _;while(_ --)solve();return0;}