-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10041.c
42 lines (41 loc) · 757 Bytes
/
10041.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
main()
{
int t,n,i,j,k,sum,a[30001];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
k=n/2;
sum=0;
for(i=0;i<n;i++)
{
if(a[k]>a[i])
{
sum+=a[k]-a[i];
}
else
{
sum+=a[i]-a[k];
}
}
printf("%d\n",sum);
}
return 0;
}