UVa 10137

From Algorithmist

Jump to: navigation, search

Contents

[edit] 10137 - The Trip

[edit] 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).

[edit] 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.

[edit] 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.)

[edit] 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

[edit] Output

$10.00
$11.99
$771.75
Personal tools