CF BUDDY
← Problems·

1978D · Elections

1600 · data structures, greedy, implementation

Problem: Elections are taking place in Berland. There are nn candidates participating in the elections, numbered from 11 to nn. The ii-th candidate has aia_i fans who will vote for him. Additionally, there are cc people who are undecided about their favorite candidate, let's call them undecided. Undecided people will vote for the candidate with the lowest number.

The candidate who receives the maximum number of votes wins the elections, and if multiple candidates receive the same maximum number of votes, the candidate with the lowest number among them wins.

You found these elections too boring and predictable, so you decided to exclude some candidates from them. If you do not allow candidate number ii to participate in the elections, all aia_i of his fans will become undecided, and will vote for the candidate with the lowest number.

You are curious to find, for each ii from 11 to nn, the minimum number of candidates that need to be excluded from the elections for candidate number ii to win the elections.

Input Format: Each test consists of multiple test cases. The first line contains a single integer tt (1t21041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and cc (1n21051 \le n \le 2 \cdot 10^5, 0c1090 \le c \le 10^9) — the number of candidates in the elections and the number of undecided people.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \le a_i \le 10^9) — the number of fans for each candidate.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output nn integers, the ii-th of which should be equal to the minimum number of candidates that need to be excluded from the elections for candidate number ii to win.

Note: In the first test case:

  • If all candidates are allowed, candidate number 11 will receive 33 votes (11 undecided person will vote for him), candidate number 22 will receive 00 votes, and candidate number 33 will receive 33 votes. Therefore, candidate number 11 wins (he received the same number of votes as candidate 33, but his number is lower), so the answer for him is 00.
  • If candidate number 11 is not allowed, his 22 fans will become undecided. Then candidate number 22 will receive 33 votes (33 undecided people will vote for him) and candidate number 33 will receive 33 votes. Therefore, candidate number 22 wins (he received the same number of votes as candidate 33, but his number is lower), so the answer for him is 11.
  • If candidates with numbers 11 and 22 are not allowed, candidate number 33 wins, so the answer for him is 22.

In the second test case, candidate number 11 will win if candidate number 22 is not allowed to participate.

Sample Cases

Case 1

Input

5
3 1
2 0 3
2 3
0 10
5 3
5 4 3 2 1
4 5
3 10 7 1
6 0
2 2 2 3 3 3

Output

0 1 2
1 0
0 1 2 3 4
1 0 2 3
1 1 2 0 4 5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback