fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define el << "\n"
  5.  
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. cout.tie(nullptr);
  10.  
  11. int t;
  12. cin >> t;
  13. while(t--){
  14. ll n,m;
  15. cin>>n>>m;
  16. ll a[1000005];
  17. for(ll i=0;i<n;i++){
  18. cin>>a[i];
  19. }
  20.  
  21. sort(a,a+n);
  22.  
  23. ll y = 0;
  24. for(ll i=0;i<n;i+=2){
  25. ll w = a[i] - a[i+1];
  26. if(w < 0){
  27. w = -w;
  28. }
  29. y += w;
  30. }
  31.  
  32. cout << y el;
  33. }
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
4 10
1 4 7 9
6 20
2 5 6 11 13 15
8 100
10 12 10 15 20 18 21 25
stdout
5
10
9