UVa 10137 - The Trip

10137 - The Trip

 * http://acm.uva.es/p/v101/10137.html

Summary
A clever arithmetic based problem related to a common task. Given a list of expenditures, find the minimum amount of money that must change hands to equalize the expenditures (within one cent).

Explanation
Calculate the average expenditure and round it to two decimal places. (You'll need to write your own rounding function). Now the expenditure can be equalized in two ways. First, by adding the amount spent minus the average amount (for spent amount > average). Then the sum rounded to two decimal places is the answer.

Implementation
Make sure to use doubles throughout. Do not round off the total.

Alternately, use only 32-bit integer variables in your solution. (Each sum we need to store is between 0 and 1,000,000,000 cents and it is possible to avoid floating-point math.)

Input
3 10.00 20.00 30.00 4 15.00 15.01 3.00 3.01 5 56.22 44.00 39.99 1.02 1000.00 0

Output
$10.00 $11.99 $771.75