UVa 591 – Box of Bricks


/*
User ID: turing_13
Link : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=532
*/

#include <iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main()
{
    int n,ara[55]= {0},i,avg,ans,b=0;
    while(scanf("%d",&n)==1 & n!=0)
    {
        b++;
        avg=ans=0;
        for(i=0; i<n; i++)
        {
            scanf("%d",&ara[i]);
            avg+=ara[i];
        }
        avg/=n;
        for(i=0; i<n; i++)
        {
            if(ara[i]>avg)
                ans+=(ara[i]-avg);
        }
        printf("Set #%d\n",b);
        printf("The minimum number of moves is %d.\n\n",ans);
    }
    return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s