fork(4) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int compare (const void* a, const void* b){
  4. return (*(int*)a-*(int*)b);
  5. }
  6. int main(void) {
  7. int c, n, s[100], i, r;
  8. scanf("%d",&c);
  9. while(c--){
  10. scanf("%d",&n);
  11. for(i=0;i<n;i++)
  12. scanf("%d",s+i);
  13. i=r=0;
  14. while(i<n-1){
  15. qsort (s, n, 4, compare);
  16. s[i+1] = s[i]+s[i+1];
  17. r+=s[++i];
  18. }
  19. printf("%d\n",r);
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 2252KB
stdin
3
3
2 2 4
5
3 1 3 4 1
8
1 1 1 1 1 1 1 2
stdout
12
26
27