CF1904B.Collecting Game

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa of nn positive integers and a score. If your score is greater than or equal to aia_i, then you can increase your score by aia_i and remove aia_i from the array.

For each index ii, output the maximum number of additional array elements that you can remove if you remove aia_i and then set your score to aia_i. Note that the removal of aia_i should not be counted in the answer.

给你一个包含 nn 个正整数的数组 aa 和一个初始分数。若你的分数大于等于 aia_i,则你可以将分数增加 aia_i,并从数组中移除 aia_i。

对每个下标 ii,输出:在首先移除 aia_i 并将你的分数设为 aia_i 的前提下,你最多还能额外移除多少个数组元素。注意:aia_i 的移除不计入答案。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤50001 \leq t \leq 5000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤50001 \leq t \leq 5000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5),表示数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示数组的元素。

保证所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case, output nn integers, the ii-th of which denotes the maximum number of additional array elements that you can remove if you remove aia_i from the array and then set your score to aia_i.

对于每个测试用例,输出 nn 个整数,其中第 ii 个整数表示:若从数组中移除 aia_i 并将你的得分设为 aia_i,则你最多还能额外移除多少个数组元素。

输入输出样例

  • 输入#1

    4
    5
    20 5 1 4 2
    3
    1434 7 1442
    1
    1
    5
    999999999 999999999 999999999 1000000000 1000000000

    输出#1

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

说明/提示

In the first test case, the answers are as follows:

If we start with i=4i=4, our initial score is a4=4a_4=4 and a=[20,5,1,2]a=[20,5,1,2]. We can remove 33 additional elements in the following order:

  1. Since 4≥14 \ge 1, we can remove 11 and our score becomes 55. After this, a=[20,5,2]a=[20,5,2].
  2. Since 5≥55 \ge 5, we can remove 55 and our score becomes 1010. After this, a=[20,2]a=[20,2].
  3. Since 10≥210 \ge 2, we can remove 22 and our score becomes 1212. After this, a=[20]a=[20].

If we start with i=1i=1 we can remove all remaining elements in the array, so the answer is 44.

If we start with i=2i=2, we can remove 33 additional elements in the following order: 11, 44, 22.

If we start with i=3i=3, we can remove no additional elements.

If we start with i=5i=5, we can remove 11 additional element: 11.

在第一个测试用例中,答案如下:

  • 如果我们从 i=4i=4 开始,初始得分为 a4=4a_4=4,此时数组为 a=[20,5,1,2]a=[20,5,1,2]。我们可以按以下顺序再移除 33 个元素:

    1. 由于 4≥14 \ge 1,我们可以移除 11,得分变为 55;移除后,a=[20,5,2]a=[20,5,2]。
    2. 由于 5≥55 \ge 5,我们可以移除 55,得分变为 1010;移除后,a=[20,2]a=[20,2]。
    3. 由于 10≥210 \ge 2,我们可以移除 22,得分变为 1212;移除后,a=[20]a=[20]。
  • 如果我们从 i=1i=1 开始,则可以移除数组中所有剩余元素,因此答案为 44。

  • 如果我们从 i=2i=2 开始,则可以按以下顺序再移除 33 个元素:11、44、22。

  • 如果我们从 i=3i=3 开始,则无法再移除任何额外元素。

  • 如果我们从 i=5i=5 开始,则只能再移除 11 个元素:11。

输入解题思路,AI测评打分。不知道怎么写?

首页