原题链接:
https://www.acwing.com/problem/content/106/
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
int n;
long long sum;
while( cin >> n )
{
sum=0;
for( int i=0;i<n;i++ )
scanf("%d",&a[i]);
sort(a,a+n);
for( int i=0;i<n/2;i++ )
{
sum+=a[n-i-1]-a[i];
}
cout << sum <<endl;
}
}