34 lines
519 B
C++
34 lines
519 B
C++
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
using ll = long long;
|
|
|
|
void solve()
|
|
{
|
|
int n;
|
|
cin>>n;
|
|
vector<int> v;
|
|
for(int i=0; i<n; ++i)
|
|
{
|
|
int x;
|
|
cin>>x;
|
|
v.push_back(x);
|
|
}
|
|
sort(v.begin(),v.end());
|
|
int cost=0;
|
|
for(int i=0, j=n-1; i<j; ++i, --j)
|
|
{
|
|
cost=cost+v[j]-v[i];
|
|
}
|
|
cout<<cost<<endl;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
ios_base::sync_with_stdio(false);
|
|
cin.tie(nullptr);
|
|
|
|
int TC = 1;
|
|
cin >> TC;
|
|
cin.ignore();
|
|
while (TC--) solve();
|
|
} |