Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<stdlib.h>
int mov(int a[],int n,int h){

int i,c=0;
for(i=0;i<n;i++){
a[i]-=h;
if(a[i]>0) c+=a[i];
}
return c;
}
int main(){
freopen("entrada.txt","r",stdin);
freopen("salida.txt","w",stdout);
int n,h,i,j,a[50],sum,b[1000];
j=0;
scanf("%d",&n);
while(n>0 && n<=50){
i=sum=0;
while(i<n) {
scanf("%d",&a[i]);
sum+=a[i];
i++;
}
h=sum/n;
if(sum%n==0){
b[j]=mov(a,n,h);
}
else break;
j++;
scanf("%d",&n);
}
for(i=0;i<j;i++){
printf("Set #%d\nThe minimum number of moves is %d.\n\n",i+1,b[i]);
}
system("pause");
return 0;
}

You might also like