2094 balanced girls-weak Edition

Source: Internet
Author: User
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 
        
       
      

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.