#include<iostream>
using namespace std;
int main()
{
int n,need,count,i;
while(5)
{
need=0,count=0;
cin>>n;
if(n==-1)
{
break;
}
else
{
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
need=need+a[i] ;
cout<<endl;
}
if(need%n!=0)
{
cout<<"-1" ;
}
else
{
for(i=0;i<n;i++)
{
if(a[i]<need/n)
{
count=count+(need/n)-a[i];
}
}
cout<<endl<<count;
}
}
}
return 0;
}
using namespace std;
int main()
{
int n,need,count,i;
while(5)
{
need=0,count=0;
cin>>n;
if(n==-1)
{
break;
}
else
{
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
need=need+a[i] ;
cout<<endl;
}
if(need%n!=0)
{
cout<<"-1" ;
}
else
{
for(i=0;i<n;i++)
{
if(a[i]<need/n)
{
count=count+(need/n)-a[i];
}
}
cout<<endl<<count;
}
}
}
return 0;
}
No comments:
Post a Comment