Charlie and Chocolates

0

0 votes
Easy
Problem

Hello folks !!!

Today is Charlie's 12th Birthday. Charlie is a very rich kid and he owns a Chocolate Factory. He invited his n friends for his birthday and distributed a random number of chocolates to each of his friend.

Now, all his friends want that the chocolates must be distributed equally among themselves. So, they decided to do so. Charlie is waiting for them at the dinner, and his friends do not want to miss the hot and spicy food.

In 1 time unit, one of the friends can give (or take) a chocolate to (or from) any other friend, while the rest of the friends remain idle during that time.

Can you help them to find the total time in which they can complete the above task as soon as possible, so that they can enjoy their dinner ?

Input:

First line of input will contain t - the number of test cases. Each of the next t cases goes as follows:

The first line of each test case will contain n - total number of friends of Charlie.
The next line will contain n space-separated integers, where the ith integer denotes the number of chocolates initially owned by the ith friend.

Output:

Print t lines, each line containing the answer to the question. If it is not possible to distribute the chocolates equally, print "-1" (without quotes).

Constraints:

1 <= t <= 100
1 <= n <= 10^5
1 <= ai <= 10^9

Here ai denotes the number of chocolates owned by the ith friend.

Problem Setter:

Devesh Jagwani

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In one time unit, 3rd friend can give a chocolate to the 1st friend. So, the minimum amount of time required to distribute the chocolates equally is 1.

Editor Image

?