Codeforces-SolutionsA/Codes/1843 A - Sasha and Array Coloring/1843A.cpp

34 lines
519 B
C++
Raw Normal View History

2023-06-23 16:31:35 +08:00
#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();
}