spoj#TRANSFER. After Party Transfers
After Party Transfers
You've been to a potluck party (party where each person contributes food), but some people are angry that they spent more money preparing their dish than the others. Now they want you (they span the bottle) to figure out how the participants of the party can, in the fewest amount of transfers, become even.
To clarify, you are free to transfer money between them in any way you like, but eventually the money they spent on their dishes, plus the money they received, minus the money the sent, must be equal for all participants.
Input
The first line contains C ∈ [0..10] - the number of test cases.
For each test case, the first line contains the number N ∈ [0..20] - the number of people at the party.
The following N lines contains a interger xi ∈ [0,10^6] representing the amount of money the ith persons dish cost.
Output
For each testcase:
The first line should be the minimal amount of transfers needed to even out the party budget.
The following lines should be on the form "a -> b: t", where a,b ∈ [0..N) and represent that person 'a' must transfer 't' money to person 'b'. t is here a floating point number of at least 6 digits precision. (Notice: that is 6 digits precision after adding together your in and out flows)
In case of multiple best solutions exists, print any.
Example
Input: 2 6 2 4 1 5 0 6 3 9 16 25
Output: 3 0 -> 1: 1.0 2 -> 3: 2.0 4 -> 5: 3.0 2 0 -> 1: 7.6666666666667 1 -> 2: 8.33333333333
Explaination:
In the first case, 3 is the minimal amount of transfers. An alternative transfer pattern would be "0 -> 3: 1 1 -> 3: 2 2 -> 4: 2 2 -> 5: 1". That would have made everyone even, but would have taken one more transfer (4).
In the second case, after the transfers, each person is down 16.666.