PROBLEM LINK:
Author: shrivas7
Tester: sandeep1103
Editorialist: shrivas7
DIFFICULTY:
EASY
PREREQUISITES:
None
EXPLANATION:
Our objective is to minimize the total problems to be solved in order to form N/2 teams.
This can we achieved if we try to minimize the no. of problems to be solved at individual
team level.Clearly if we want to do so we must make sure that the difference between the programming skills of the pair forming the team should be as minimum as possible.
Therefore we need to sort the array containing the programming skills of N students , and thereafter we can take pairs of students serially and form their team ,and the keep on calculating the minimum problems to be solved .
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,i;
cin>>t;
while(t--)
{
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int ans=0;
for(i=0;i<=n-2;i+=2)
ans += a[i+1]-a[i];
cout<<ans<<endl;
}
}