| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位大牛.指点下。 哪里错了。??#include <stdio.h>
#include <stdlib.h>
#include <string.h>
long l[100000];
long left[1000000];
int compare(const void *a, const void *b) {
return *(long *)a - *(long *)b;
}
int main() {
//freopen("pku2231.in", "r", stdin);
//freopen("pku2231.out", "w+", stdout);
int n;
__int64 result;
while (scanf("%d", &n) == 1) {
result = 0;
for (int i = 1; i <= n; i++) {
scanf("%ld", &l[i]);
}
if (n == 0) {
printf("0\n");
continue;
}
qsort(&l[1], n, sizeof(long), compare);
left[1] = 0;
for (int i = 2; i <= n; i++) {
left[i] = left[i - 1] + (i - 1) * (l[i] - l[i - 1]);
result += left[i];
}
printf("%I64d\n", 2 * result);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator