poj2231

简单题

View Code
   
     
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
#include
< algorithm >
using namespace std;

#define maxn 10006

int f[maxn];

int main()
{
// freopen("t.txt", "r", stdin);
int n;
scanf(
" %d " , & n);
for ( int i = 0 ; i < n; i ++ )
scanf(
" %d " , & f[i]);
sort(f, f
+ n);
long long ans = 0 , sum = 0 ;
for ( int i = 1 ; i < n; i ++ )
{
sum
+= (( long long )(f[i] - f[i - 1 ])) * i;
ans
+= sum;
}
printf(
" %lld\n " , ans * 2 );
return 0 ;
}

你可能感兴趣的:(poj)