#include<stdio.h>
int main(){
long long int sum,sumr;
int p,ar[10000],l,i,x;
while(1){
sum=0;
sumr=0;
scanf("%d",&p);
if(p==-1)
break;
for(i=0;i<p;i++){
scanf("%d",&ar[i]);
sum=sum+ar[i];
}
l=sum%p;
if(l==0){
x=sum/p;
for(i=0;i<p;i++){
if(ar[i]>x)
sumr=sumr+(ar[i]-x);
}
printf("%lld\n",sumr);
}
else
printf("-1\n");
}
return 0;
}
int main(){
long long int sum,sumr;
int p,ar[10000],l,i,x;
while(1){
sum=0;
sumr=0;
scanf("%d",&p);
if(p==-1)
break;
for(i=0;i<p;i++){
scanf("%d",&ar[i]);
sum=sum+ar[i];
}
l=sum%p;
if(l==0){
x=sum/p;
for(i=0;i<p;i++){
if(ar[i]>x)
sumr=sumr+(ar[i]-x);
}
printf("%lld\n",sumr);
}
else
printf("-1\n");
}
return 0;
}
No comments:
Post a Comment