fork(1) download
  1. #include <stdlib.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7. int *array= NULL;
  8. int n=0,t,sum=0,i=0,j=0;
  9.  
  10. cin >> t;
  11. if(t==0)
  12. t=-1;
  13. while(t!=-1){
  14. n=0;
  15. sum=0;
  16. j=t;
  17.  
  18. if(t>10000)
  19. exit(0);
  20.  
  21. array = new int[j];
  22. while(j>0){
  23. cin >> array[j-1];
  24. sum+=array[j-1];
  25. j--;
  26. }
  27. if(sum%t!=0){
  28. cout << -1 << endl;
  29. delete [] array;
  30. array = NULL;
  31. cin >> t;
  32. if(t==0)
  33. t=-1;
  34. continue;
  35. }
  36.  
  37. j=t;
  38. while(j>0){
  39. i=abs(array[j-1]-(sum/t));
  40. if(array[j-1]<(sum/t))
  41. n+=i;
  42. j--;
  43. }
  44. cout << n << endl;
  45. delete [] array;
  46. array = NULL;
  47. cin >> t;
  48. if(t==0)
  49. t=-1;
  50. }
  51. }
  52.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty