Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created April 7, 2015 01:59
Show Gist options
  • Save henrybear327/dca7d11a5d90405d277a to your computer and use it in GitHub Desktop.
Save henrybear327/dca7d11a5d90405d277a to your computer and use it in GitHub Desktop.
w5b.c debug
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
long long int x[1000]= {0},m;
scanf("%lld",&m);
long long int i,j,sum=0,temp=0;
for(i=0; i<m; i++)
scanf("%lld",&x[i]);
for(i=0; i<m; i++)
{
for(j=i; j<m-1; j++)
{
if(x[j]>x[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
for(i=0;i<m;i++)
{
sum+=x[i]*(2*(m-i)-1);
}
printf("%lld\n",sum);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment