Uva 591 - Box of Bricks Solution
Problem Link
Uva 591 - Box of Bricks Solution
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,j=1;
cin>>n;
while(n!=0)
{
int a[n+2],i,max=0,ans=0;
for(i=0; i<n; i++ )
{
cin>>a[i];
max+=a[i];
}
max=max/n;
for(i=0;i<n;i++)
{
if(a[i]>max)
ans+=a[i]-max;
}
cout<<"Set #"<<j<<endl;
cout<<"The minimum number of moves is "<<ans<<"."<<endl<<endl;
j++;
cin>>n;
}
return 0;
}
No comments