fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long LL;
  5. typedef unsigned long long ULL;
  6. typedef vector<int> VI;
  7. typedef vector<LL> VLL;
  8. typedef pair<int, int> PI;
  9.  
  10. #define SI(x) scanf("%d", &x)
  11. #define SLL(x) scanf("%lld", &x)
  12. #define SORTV(v) sort(v.begin(), v.end())
  13. #define EACH(it, v) for(__typeof(v.begin()) it(v.begin()); it != v.end(); it++)
  14. #define pb(x) push_back(x)
  15. #define mp(x, y) make_pair(x, y)
  16. #define f first
  17. #define s second
  18.  
  19. template<class T> void print_array(T a[], int size) { for(int i=0; i<size; i++) cout<<a[i]<<" "; cout<<endl; }
  20.  
  21. template<class T> void print_array_v(T &a) { int size = a.size(); for(int i=0; i<size; i++) cout<<a[i]<<" "; cout<<endl; }
  22.  
  23. int main()
  24. {
  25. int T;
  26. scanf("%d", &T);
  27. assert(T<=10);
  28. while(T--)
  29. {
  30. int n; SI(n); assert(n<=1e3);
  31. int a[1010];
  32. for(int i=0; i<n; i++)
  33. {
  34. SI(a[i]);
  35. assert(a[i] <= 1e6);
  36. }
  37. sort(a, a+n);
  38. int sum = 0;
  39. for(int i=0; i<n/2; i++)
  40. sum += a[n-i-1] - a[i];
  41. cout<<sum<<endl;
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty