能在水一点么。。。
#include <stdio.h>
#include <algorithm>
#define N 505
int a[N];
int main()
{
int t, n, mid, sum, tmp;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
std::sort(a, a + n);
mid = n >> 1;
tmp = a[mid];
sum = 0;
for(int i = 0; i < n; i++)
sum += abs(a[i] - tmp);
printf("%d\n", sum);
}
return 0;
}