HDOJ 2088
1 #include<cstdio> 2 int main() 3 { 4 int a[51],i,j,n,x,k=1; 5 int sum,ans; 6 while(scanf("%d",&n)!=EOF&&n) 7 { 8 sum=ans=0; 9 if(!k) 10 printf("\n"); 11 k=0; 12 for(i=0;i<n;i++) 13 { 14 scanf("%d",&a[i]); 15 sum+=a[i]; 16 } 17 int aver=sum/n; 18 for(i=0;i<n;i++) 19 if(a[i]>aver) 20 ans+=a[i]-aver; 21 printf("%d\n",ans); 22 } 23 return 0; 24 }