initial commit

This commit is contained in:
ShazidMahsrafi 2023-06-23 14:31:35 +06:00
parent 0482f2cd40
commit 3f3cc6ca7e

View File

@ -0,0 +1,34 @@
#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();
}