DMOPC '15 Contest 3 P2 - Cheesecake Distribution
View as PDF has managed to survive his first semester English course so far. To celebrate, he invited  friends over for a party!
For dessert, he decided to cut  some cheesecake. 's friends are greedy. As soon as he finished, his friends grabbed all the slices that they could.  is a strong proponent of equality, so he would like to redistribute the slices such that each friend gets the same amount. He will do this by persuading a friend with the maximum number of slices to give  slice to a friend with the minimum number of slices, and repeating this process until the slices are equally distributed. Since 's friends are also stubborn, so it will take him 
 minute to convince them each time.
wants to know how long it will take for him to evenly distribute the cheesecake slices.
Input Specification
The first line of input will contain  
, the number of friends.
The next line will contain  space-separated nonnegative integers, the number of slices that each friend grabbed. Each friend will have no more than 
 slices. (It's a really big cheesecake)
Output Specification
Output one integer, the number of minutes it will take for  to evenly distribute the cheesecake following this process. If this is not possible, output Impossible.
Note
The input and output may not fit in 32-bit integer variables. Please use 64-bit integer variables (such as long in Java and long long in C/C++).
Sample Input 1
3
6 1 2
Sample Output 1
3
Explanation for Sample Output 1
will perform the following steps:
- Ask friend 
to give a slice to friend
.
 - Ask friend 
to give a slice to friend
.
 - Ask friend 
to give a slice to friend
.
 
Sample Input 2
2
1 2
Sample Output 2
Impossible
Explanation for Sample Output 2
No matter what does, one friend will always have more than the other.
Sample Input 3
10
3 5 4 6 5 2 4 6 9 6
Sample Output 3
7
Comments
IDK what's wrong with my C++ 14 code, it keeps saying Batch 5 testcase 1 is WA. I have an output of Impossible.
EDIT: NVM I put long long int instead of long long
I tried my code with all the test cases and my own case, but it still says that batch 4 has the wrong answer. What is wrong with my code?
Each friend can already have the same amount of slices.
Hmmmm when I'm testing my code it works. but when I submit it, it says it's incorrect.....
Your code has a tiny little mistake in it. Just remember to be careful with indentation in python and you will find it.
uh, FatalEagle, are you communist?
In his defense, the problem statement does say,
We're led to believe that there are not many slices left, since FatalEagle was there first!