Created
September 15, 2018 09:47
-
-
Save completejavascript/5726f391a1a1f5e5453cc123fe0581b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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