Wednesday, January 22, 2014

UVa 591 - Box of Bricks solution

Problem link :  UVa 591 - Box of Bricks

Solution : 


#include<stdio.h>
int main()
{
    int a[105],n,sum,avg,k,i,st=1;
    while(scanf("%d",&n)==1)
    {
        if(n==0) break;
        sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        avg=sum/n; k=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]>avg) k+=(a[i]-avg);
        }
        printf("Set #%d\n",st); st++;
        printf("The minimum number of moves is %d.\n\n",k);
    }
    return 0;
}




No comments:

Post a Comment