This page is still under construction.

Parts of this page are still being built. What you see may change.

Balloon Distribution

Time limit6sMemory limit512 MB

Summary
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 MM contestants. Contestant ii scored PiP_i points, for i=1,2,…,Mi = 1, 2, \dots, M.

The organizers have NN balloons and hand them out by the following rule.

  1. For every contestant ii and every positive integer j=1,2,3,…j = 1, 2, 3, \dots, compute the ratio Pi/jP_i / j.
  2. 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.
  3. A contestant receives one balloon for each of their own ratios whose rank is at most NN. 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 NN.

Report how many balloons each contestant receives.

For example, take M=5M = 5 contestants with P1=274771P_1 = 274771, P2=344854P_2 = 344854, P3=773780P_3 = 773780, P4=627629P_4 = 627629, P5=386890P_5 = 386890, and N=10N = 10 balloons. The ratios, rounded to two decimals, start like this.

j = 1j = 2j = 3j = 4j = 5...
#1274771.00137385.5091590.3368692.7554954.20...
#2344854.00172427.00114951.3386213.5068970.80...
#3773780.00386890.00257926.67193445.00154756.00...
#4627629.00313814.50209209.67156907.25125525.80...
#5386890.00193445.00128963.3396722.5077378.00...

Their ranks are below. A rank in bold is at most N=10N = 10, so that ratio earns a balloon. Every ratio with j≥6j \ge 6 has a rank greater than 10 here.

j = 1j = 2j = 3j = 4j = 5...
#1715243443...
#2512192633...
#31381014...
#42691318...
#5310162229...

The five contestants therefore receive 1, 1, 4, 3, and 2 balloons. That is 11 balloons in total, because 773780/4773780 / 4 and 386890/2386890 / 2 are both equal to 193445193445 and tie at rank 10.

Input

The first line contains TT, the number of test cases.

Each test case takes two lines. The first line contains two integers MM and NN separated by a space. The second line contains MM space separated integers P1,P2,…,PMP_1, P_2, \dots, P_M.

Constraints:

  • 1≤T≤30001 \le T \le 3000
  • 1≤M≤1051 \le M \le 10^5
  • the sum of MM over all test cases is at most 4×1054 \times 10^5
  • 1≤N≤1091 \le N \le 10^9
  • 1≤Pi≤1091 \le P_i \le 10^9

Output

For each test case, print one line with MM integers separated by single spaces. The ii-th integer is the number of balloons contestant ii receives.

Examples2

  1. Example 1

    Input
    2
    5 10
    274771 344854 773780 627629 348561
    5 10
    274771 344854 773780 627629 386890
    
    Expected output
    1 1 4 3 1
    1 1 4 3 2
    
  2. Example 2

    Input
    3
    5 7
    2 2 2 2 2
    4 1
    5 5 5 5
    3 5
    6 6 6
    
    Expected output
    2 2 2 2 2
    1 1 1 1
    2 2 2