All submissions for this problem are available.
On the eve of Republic Day, Teacher decided to distribute candies among N students.She brought the candies in a box and
placed it in front of students. She allowed every student to take out some candies. But each one of them tried
to take out as much candies as possible. That's why, Not all students were happy. She called all students and
requested for their bags of candies. Now she wants to distribute candies equally among all bags. She'll be performing
- Pick up a candy from a bag.
- Put a candy into another bag.
Both operations require 1 unit of time. You are given with bags of N students with number of candies
in it. You have to check whether candies can be distributed equally among all bags or not. If it can be distributed then
calculate the time required for total distribution.
- First Line contains number of test cases T.
- Every test case consist of two lines, First line contains N i.e. Number of Bags and next line contains N
space separated integers A1, A2, ..., AN , where ith integer
indicates number of candies in ith bag.
- If candies can be distributed equally then output the time required for distribution in new line,
- else, output "-1" (without quotes) in new line.
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 100
- 0 ≤ Number of Candies in each bag ≤ 1000
Input: 3 3 1 2 3 3 1 2 1 4 9 7 8 0 Output: 2 -1 12
Example case 1.Teacher picks up a candy from a bag with maximum candies i.e. 3rd bag and put it in the bag with minimum candies i.e. 1st bag. Now all bags have two candies each. Total time required for distribution is 2.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, SCM chicken, CLOJ, FS|
Fetching successful submissions