Help me in solving MAXSCORE7 problem

My issue

Explain the problem statement

My code

#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<int> A(n);

        for (int i = 0; i < n; ++i) {
            cin >> A[i];
        }

         sort(A.begin(), A.end());
        long long s = 0;
        
        for (int i = 0; i < n-1; i+=2) {
            s+= abs(A[i] - A[i+1]);
        }

        cout << s << endl;
    }

    return 0;
}

Problem Link: Maximum Score Practice Coding Problem - CodeChef

@bitwise_sameer
plzz refer my c++ code for better understanding of the logic

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    int cnt=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        if(a[i]==1)
	        cnt++;
	    }
	    cout<<min(cnt,(n-cnt))<<endl;
	}
	return 0;
}