C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
int n;
int a[N];
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
sort(a, a + n);
int res = 0;
for(int i = 0; i < n; i += 2) res += abs(a[i] - a[i + 1]);
cout << res << endl;
}