CF1870D.Prefix Purchase

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array aa of size nn, initially filled with zeros (a1=a2=…=an=0a_1 = a_2 = \ldots = a_n = 0). You also have an array of integers cc of size nn.

Initially, you have kk coins. By paying cic_i coins, you can add 11 to all elements of the array aa from the first to the ii-th element (aj+=1a_j \mathrel{+}= 1 for all 1≤j≤i1 \leq j \leq i). You can buy any cic_i any number of times. A purchase is only possible if k≥cik \geq c_i, meaning that at any moment k≥0k \geq 0 must hold true.

Find the lexicographically largest array aa that can be obtained.

An array aa is lexicographically smaller than an array bb of the same length if and only if in the first position where aa and bb differ, the element in array aa is smaller than the corresponding element in bb.

你有一个长度为 nn 的数组 aa,初始时所有元素均为零(即 a1=a2=…=an=0a_1 = a_2 = \ldots = a_n = 0)。你还拥有一个长度为 nn 的整数数组 cc。

初始时你有 kk 枚硬币。花费 cic_i 枚硬币,你可以将数组 aa 的前 ii 个元素各加 11(即对所有 1≤j≤i1 \leq j \leq i,执行 aj+=1a_j \mathrel{+}= 1)。你可以任意多次购买任意一个 cic_i。一次购买仅在 k≥cik \geq c_i 时可行,即在任意时刻都必须满足 k≥0k \geq 0。

求所能得到的字典序最大的数组 aa。

当且仅当在数组 aa 与同长度数组 bb 首次出现差异的位置上,aa 中对应元素小于 bb 中对应元素时,称数组 aa 字典序小于数组 bb。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. This is followed by a description of the test cases.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the size of arrays aa and cc.

The second line of each test case contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (1≤ci≤1091 \leq c_i \leq 10^9) — the array cc.

The third line of each test case contains a single integer kk (1≤k≤1091 \leq k \leq 10^9) — the number of coins you have.

It is guaranteed that the sum of all nn values across all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 表示数组 aa 和 cc 的大小。

每个测试用例的第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(1≤ci≤1091 \leq c_i \leq 10^9)—— 即数组 cc。

每个测试用例的第三行包含一个整数 kk(1≤k≤1091 \leq k \leq 10^9)—— 表示你拥有的硬币数量。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers a1,a2,…,ana_1, a_2, \ldots, a_n — the lexicographically largest array aa that can be obtained.

对于每个测试用例,输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n —— 可以得到的字典序最大的数组 aa。

输入输出样例

  • 输入#1

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

    输出#1

    5 0 0 
    2 1 
    2 2 2 
    2 2 2 2 2 1

说明/提示

In the first test case, a1a_1 cannot be greater than 55, and if we buy c1c_1 five times, we will run out of money, so a=[5,0,0]a = [5, 0, 0].

In the second test case, a1a_1 cannot be greater than 22, but we can buy c1c_1 and c2c_2 once each (buying c2c_2 twice is not possible), so a=[2,1]a = [2, 1].

在第一个测试用例中,a1a_1 不能大于 55;如果我们购买 c1c_1 五次,资金将耗尽,因此 a=[5,0,0]a = [5, 0, 0]。

在第二个测试用例中,a1a_1 不能大于 22;但我们可各购买一次 c1c_1 和 c2c_2(无法购买两次 c2c_2),因此 a=[2,1]a = [2, 1]。

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

首页