标签:
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
Input
Output
Sample Input
5 1 5 3 2 4
Sample Output
40
Hint
#include<cstdio> #include<iostream> #include<cstring> #include<stdlib.h> #include<algorithm> #include<cmath> using namespace std; #define N 10005 int c[N]; int main() { int n,i,j; long long ans; while(scanf("%d",&n)!=EOF) { ans=0; for(i=0;i<n;i++) { scanf("%d",&c[i]); } sort(c,c+n); for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { ans+=2*abs(c[i]-c[j]); } } printf("%lld\n",ans);} return 0; }
标签:
原文地址:http://www.cnblogs.com/Annetree/p/5824102.html