Problem Statement

There are some bottles on the table. The i-th bottle contains waterVolumes[i] liters of water. You can pour out water from any bottle to any other. The volume of water you pour out is not necessarily an integer. It takes 1 second to pour 1 liter of water. Each bottle is large enough to contain as much water as you want.

Return the minimal time in seconds required to make each bottle contain an equal volume of water.

Definition

 Class: WaterEqualizer Method: minTime Parameters: int[] Returns: double Method signature: double minTime(int[] waterVolumes) (be sure your method is public)

Notes

-The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints

-waterVolumes will contain between 1 and 50 elements, inclusive.
-Each element of waterVolumes will be between 1 and 10, inclusive.

Examples

0)

 `{1, 2}`
`Returns: 0.5`
 Pour out 0.5 liter from the second bottle to the first.
1)

 `{1, 2, 1, 2}`
`Returns: 1.0`
 Pour out 0.5 liter from the second bottle to the first and from the fourth to the third.
2)

 `{10, 1}`
`Returns: 4.5`
3)

 `{1, 2, 3, 4}`
`Returns: 2.0`

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9715

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12228&pm=9715

Mike Mirzayanov

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Simulation