fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define true 1
  4. #define false 0
  5. int main(void) {
  6. int lpowt,liczbad= 0;
  7. scanf("%d",&lpowt);
  8. for(int i = 0; i < lpowt; i++){
  9. scanf("%d", &liczbad);
  10. int min = 0,max = 0;
  11. int tab[liczbad];
  12. int ltab[liczbad];
  13. for( int x = 0; x < liczbad;x++){
  14. scanf("%d",&tab[x]);
  15. }
  16. int tmp;
  17. for(int x = 0 ; x < liczbad; x++){
  18. for(int s = 0 ; s < liczbad - 1; s++){
  19. if(tab[s] < tab[s + 1]){
  20. tmp = tab[s];
  21. tab[s] = tab[s + 1];
  22. tab[s + 1] = tmp;
  23. }
  24. }
  25. }
  26. for(int x = 0 ; x < liczbad; x++){
  27. max += tab[x];
  28. }
  29. int sum = 0;
  30. int nsum = 0;
  31. int halfmax = max / 2;
  32. for(int x = 0 ; x < liczbad; x++){
  33. if(tab[x] + sum <= halfmax){
  34. sum += tab[x];
  35. ltab[x] = true;
  36. }else{
  37. ltab[x] = false;
  38. }
  39. }
  40. for( int x = 0; x < liczbad;x++){
  41. if(ltab[x] == false){
  42. nsum += tab[x];
  43. }
  44. }
  45. printf("%d %d \n",abs(sum - nsum),max);
  46. }
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 5312KB
stdin
1
1
8
stdout
Standard output is empty