Description
We all know that the number of girls in these schools is different,
Now, the college-university community has made a decision that does not actually exist, that is, to balance the girls in these colleges and universities. The so-called balance means that the number of girls in these colleges is the same. This involves moving girls.
Girls move to another school. Moving a girl from one school to another consumes one unit,
Of course, moving y girls from one school to another requires a price of Y. Now we provide the number of girls in n colleges and universities. I hope you can calculate whether or not you can achieve this goal. If you can, what is the minimum price.
-
-
Input
-
-
Multiple groups of test data, each group of test data occupies two rows, the first row is an integer N (1 <= n <= 20), and the second row has n integers: A1, a2 ,..., AI ,..., an, indicating the number of girls in the n colleges. (AI> = 0, int In the int range)
Output
If the goal described in the question can be achieved, the minimum cost will be output. If not, output-1. For each group of test data, the output occupies one row.
The result is within the int range.
Sample Input
3
6 8 9
3
9 8 10
Sample output
-1
1
simulated question
# include
int main () {int N, I, sum, average; int A [101]; int answer; while (scanf ("% d", & N )! = EOF) {sum = 0; answer = 0; for (I = 0; I