1904B.md (2298B)
1 Source: https://codeforces.com/problemset/problem/1904/B 2 3 B. Collecting Game 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given an array $a$ of $n$ positive integers and a score. If your score is greater than or equal to $a_i$, then you can increase your score by $a_i$ and remove $a_i$ from the array. 22 23 For each index $i$, output the maximum number of additional array elements that you can remove if you remove $a_i$ and then set your score to $a_i$. Note that the removal of $a_i$ should not be counted in the answer. 24 25 Input 26 27 Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 5000$) — the number of test cases. The description of the test cases follows. 28 29 The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the array. 30 31 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. 32 33 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 34 35 Output 36 37 For each test case, output $n$ integers, the $i$-th of which denotes the maximum number of additional array elements that you can remove if you remove $a_i$ from the array and then set your score to $a_i$. 38 39 Example 40 41 Input 42 43 ``` 44 4 45 46 5 47 48 20 5 1 4 2 49 50 3 51 52 1434 7 1442 53 54 1 55 56 1 57 58 5 59 60 999999999 999999999 999999999 1000000000 1000000000 61 ``` 62 63 Output 64 65 ``` 66 4 3 0 3 1 67 1 0 2 68 0 69 4 4 4 4 4 70 ``` 71 72 Note 73 74 In the first test case, the answers are as follows: 75 76 If we start with $i=4$, our initial score is $a_4=4$ and $a=[20,5,1,2]$. We can remove $3$ additional elements in the following order: 77 78 1. Since $4 \ge 1$, we can remove $1$ and our score becomes $5$. After this, $a=[20,5,2]$. 79 2. Since $5 \ge 5$, we can remove $5$ and our score becomes $10$. After this, $a=[20,2]$. 80 3. Since $10 \ge 2$, we can remove $2$ and our score becomes $12$. After this, $a=[20]$. 81 82 If we start with $i=1$ we can remove all remaining elements in the array, so the answer is $4$. 83 84 If we start with $i=2$, we can remove $3$ additional elements in the following order: $1$, $4$, $2$. 85 86 If we start with $i=3$, we can remove no additional elements. 87 88 If we start with $i=5$, we can remove $1$ additional element: $1$.