Compute for each contestant the smallest vote percentage that guarantees another contestant ties or trails them no matter how the remaining votes split.
Medium5MathBinary searchSortingNo attempts yetTime limit5sMemory limit512 MBA reality TV show has N contestants. Each contestant gets a score from the judges, and the audience vote is added on top of it to form a final score.
Let X be the sum of the judge scores of all contestants. If a contestant received J points from the judges and a fraction Y of the audience vote, where 0≤Y≤1 (for example 0.3), then that contestant's final score is J+X⋅Y. The vote fractions of all contestants add up to exactly 1.
The contestant with the lowest final score is eliminated. If two or more contestants share the lowest score, nobody is eliminated.
Once contestant i's vote fraction is fixed at Y, the remaining fraction 1−Y can be split among the other contestants in any way, with a nonnegative amount for each of them. Given the judge scores, find for every contestant the smallest Y, as a percentage, that keeps that contestant out of elimination no matter how the remaining votes are split.
The first line contains the number of test cases T. Each of the next T lines holds one test case. A line starts with the number of contestants N, then a single space, then the judge scores s0,s1,…,sN−1 separated by single spaces. The value si is the score contestant i received from the judges.
Print one line per test case. The line starts with Case #x: , then the real numbers m0,m1,…,mN−1 separated by single spaces. Here x is the test case number starting from 1, and mi is the smallest percentage of the audience vote contestant i must secure to be certain of avoiding elimination.
Always print mi with exactly six digits after the decimal point. Round the exact value at the seventh digit after the decimal point, rounding up when that digit is exactly 5. A value of 0 prints as 0.000000 and a value of 100 prints as 100.000000.