Balloon Distribution
Time limit6sMemory limit512 MB
Rank all ratios P_i/j from largest to smallest and count, for each contestant, how many ratios fall at rank N or above, with ties at the cutoff all counted.
- Level
Hard8 of 10
- Topics
- Binary search, Sorting, Math, Greedy
- Solved
- No attempts yet
Problem
A contest has contestants. Contestant scored points, for .
The organizers have balloons and hand them out by the following rule.
- For every contestant and every positive integer , compute the ratio .
- Collect all of these ratios into one list and rank them from the largest value down to the smallest. Equal ratios share the same rank: the rank of a ratio is one plus the number of ratios strictly larger than it.
- A contestant receives one balloon for each of their own ratios whose rank is at most . When several ratios tie at the last rank that still earns a balloon, every ratio tied there earns one, so the number of balloons handed out can be larger than .
Report how many balloons each contestant receives.
For example, take contestants with , , , , , and balloons. The ratios, rounded to two decimals, start like this.
Their ranks are below. A rank in bold is at most , so that ratio earns a balloon. Every ratio with has a rank greater than 10 here.
The five contestants therefore receive 1, 1, 4, 3, and 2 balloons. That is 11 balloons in total, because and are both equal to and tie at rank 10.
Input
The first line contains , the number of test cases.
Each test case takes two lines. The first line contains two integers and separated by a space. The second line contains space separated integers .
Constraints:
- the sum of over all test cases is at most
Output
For each test case, print one line with integers separated by single spaces. The -th integer is the number of balloons contestant receives.