#include<iostream>
using namespace std;
void anik(int f[], int n)
{
int i, j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(f[j] >f[j+1])
{
swap(f[j], f[j+1]);
}
}
}
}
int main()
{
int t, r, i, b, c, x, n, m = 0 ;
cin >> t;
while(t--)
{
cin >> r;
int a[r];
for(i=0;i<r;i++)
{
cin >> a[i];
}
anik(a , r);
if(r%2 == 0)
{
b = (r/2) -1, c = r/2;
x = (a[b] + a[c])/2;
}
else
{
b = ((r+1)/2) - 1;
x = a[b];
}
for(i=0;i<r;i++)
{
n = a[i] - x;
if(n < 0)
n = n * (-1);
m = m + n;
}
cout << m << endl;
m = n = 0;
}
return 0;
}
using namespace std;
void anik(int f[], int n)
{
int i, j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(f[j] >f[j+1])
{
swap(f[j], f[j+1]);
}
}
}
}
int main()
{
int t, r, i, b, c, x, n, m = 0 ;
cin >> t;
while(t--)
{
cin >> r;
int a[r];
for(i=0;i<r;i++)
{
cin >> a[i];
}
anik(a , r);
if(r%2 == 0)
{
b = (r/2) -1, c = r/2;
x = (a[b] + a[c])/2;
}
else
{
b = ((r+1)/2) - 1;
x = a[b];
}
for(i=0;i<r;i++)
{
n = a[i] - x;
if(n < 0)
n = n * (-1);
m = m + n;
}
cout << m << endl;
m = n = 0;
}
return 0;
}
Comments
Post a Comment