fork(1) download
  1.  
  2. // In Practice, You should use the statndard input/output
  3. // in order to receive a score properly.
  4. // Do not use file input and output. Please be very careful.
  5.  
  6. #include <stdio.h>
  7.  
  8. int main(void)
  9. {
  10. int tc, T;
  11.  
  12. // The freopen function below opens input.txt file in read only mode, and afterward,
  13. // the program will read from input.txt file instead of standard(keyboard) input.
  14. // To test your program, you may save input data in input.txt file,
  15. // and use freopen function to read from the file when using scanf function.
  16. // You may remove the comment symbols(//) in the below statement and use it.
  17. // But before submission, you must remove the freopen function or rewrite comment symbols(//).
  18.  
  19. // freopen("input.txt", "r", stdin);
  20.  
  21. // If you remove the statement below, your program's output may not be rocorded
  22. // when your program is terminated after the time limit.
  23. // For safety, please use setbuf(stdout, NULL); statement.
  24.  
  25.  
  26. scanf("%d", &T);
  27. for(tc = 0; tc < T; tc++)
  28. {
  29.  
  30. /**********************************
  31. * Implement your algorithm here. *
  32. ***********************************/
  33. int n;
  34. scanf("%d",&n);
  35. int i,a[n],sum=0;
  36. for(i=0;i<n;i++) {
  37. scanf("%d",&a[i]);
  38. sum+=a[i];
  39. }
  40. int key=(sum/n),ans=0;
  41. for(i=0;i<n;i++) {
  42. if(a[i]>key)
  43. ans+=(a[i]-key);
  44. }
  45. // Print the answer to standard output(screen).
  46. printf("%d\n",ans);
  47. }
  48.  
  49. return 0;//Your program should return 0 on normal termination.
  50. }
  51.  
Success #stdin #stdout 0.01s 5436KB
stdin
25
0 18 35 2 31 33 32 6 11 15 36 19 42 23 9 20 24 3 10 47 8 38 5 37 46
stdout
0
105
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819
641122819