Problem Type : Ad hoc
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int arr[1000],t,n,i,j,sum;
while(scanf("%d",&t)==1)
{
for(i=1; i<=t; i++)
{
sum=0;
scanf("%d",&n);
for(j=0; j<n; j++)
{
scanf("%d",&arr[j]);
}
sort(arr,arr+n);
for(j=n-1; j>0; j--)
{
sum+=arr[j]-arr[j-1];
}
sum*=2;
printf("%d\n",sum);
}
}
return 0;
}
No comments:
Post a Comment