Advertisement
Naib_greylo1999

Untitled

Mar 29th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,i,cnt,sum=0,d,sum1=0,k=1;
  6.  
  7. while(scanf("%d",&n),n)
  8. {
  9.  
  10. int a[n];
  11.  
  12. for(i=0;i<n;i++)
  13. {
  14. cin>>a[i];
  15.  
  16. sum=sum+a[i];
  17. }
  18. d=sum/n;
  19. for(i=0;i<n;i++)
  20. {
  21. if(a[i]>d)
  22. {
  23. cnt=a[i]-d;
  24. sum1=sum1+cnt;
  25. }
  26. }
  27. printf("Set #%d\n",k);
  28. cout<<"The minimum number of moves is"<<" "<<sum1<<"."<<endl<<endl;
  29. sum=0;
  30. sum1=0;
  31. k++;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement