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;
}

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments