SBRICKS - Stacks of Bricks

Problem statement

You are given a sequence of n (n < 100) integers. Each number denotes the height of a stack of bricks. If we put the stacks in a line as in the illustration below, we would see stacks of uneven heights. Suppose a “move” is made by picking up one brick from one stack and putting it on another, compute the minimum number of moves to rearrange the bricks such that all stacks have the same height.

Read the input from standard input. The first line of the input is the integer n, followed by n lines of integers denoting the height of the n stacks. The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height. Your output to standard output should consist of exactly one integer denoting the minimum number of moves.

Sample input

6
5
2
4
1
7
5

Sample output

5


Added by:Zhang Zhiyong Melvin
Date:2009-11-04
Time limit:0.200s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC PERL6 SQLITE VB.NET

hide comments
2015-04-20 19:41:03 naina roy
Why am I getting a result showing 100? what does that mean? its in green but the result is not showing "accepted"
2011-05-29 06:36:05 Santiago Palacio
Why did you do that? delete that link please, you should not post your solution here.
Besides, it's not even the right solution.

Last edit: 2011-05-29 06:48:11
2010-07-31 16:33:40 :(){ :|: & };:

Same as Candy.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.