Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/5726f391a1a1f5e5453cc123fe0581b5 to your computer and use it in GitHub Desktop.
Save completejavascript/5726f391a1a1f5e5453cc123fe0581b5 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
//freopen("input.txt","r",stdin);
int n = 0;
while(true)
{
cin >> n;
if(n == -1) break;
int sum = 0;
int *a = new int[n];
for(int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
}
int moves = 0;
if(sum % n != 0) moves = -1;
else
{
int average = sum / n;
for(int i = 0; i < n; i++)
if(a[i] < average) moves += average - a[i];
}
cout << moves << endl;
delete[] a;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment