CF1870D.Prefix Purchase
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an array a of size n, initially filled with zeros (a1=a2=…=an=0). You also have an array of integers c of size n.
Initially, you have k coins. By paying ci coins, you can add 1 to all elements of the array a from the first to the i-th element (aj+=1 for all 1≤j≤i). You can buy any ci any number of times. A purchase is only possible if k≥ci, meaning that at any moment k≥0 must hold true.
Find the lexicographically largest array a that can be obtained.
An array a is lexicographically smaller than an array b of the same length if and only if in the first position where a and b differ, the element in array a is smaller than the corresponding element in b.
你有一个长度为 n 的数组 a,初始时所有元素均为零(即 a1=a2=…=an=0)。你还拥有一个长度为 n 的整数数组 c。
初始时你有 k 枚硬币。花费 ci 枚硬币,你可以将数组 a 的前 i 个元素各加 1(即对所有 1≤j≤i,执行 aj+=1)。你可以任意多次购买任意一个 ci。一次购买仅在 k≥ci 时可行,即在任意时刻都必须满足 k≥0。
求所能得到的字典序最大的数组 a。
当且仅当在数组 a 与同长度数组 b 首次出现差异的位置上,a 中对应元素小于 b 中对应元素时,称数组 a 字典序小于数组 b。
输入格式
The first line contains a single integer t (1≤t≤104) — 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 n (1≤n≤2⋅105) — the size of arrays a and c.
The second line of each test case contains n integers c1,c2,…,cn (1≤ci≤109) — the array c.
The third line of each test case contains a single integer k (1≤k≤109) — the number of coins you have.
It is guaranteed that the sum of all n values across all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 表示数组 a 和 c 的大小。
每个测试用例的第二行包含 n 个整数 c1,c2,…,cn(1≤ci≤109)—— 即数组 c。
每个测试用例的第三行包含一个整数 k(1≤k≤109)—— 表示你拥有的硬币数量。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output n integers a1,a2,…,an — the lexicographically largest array a that can be obtained.
对于每个测试用例,输出 n 个整数 a1,a2,…,an —— 可以得到的字典序最大的数组 a。
输入输出样例
输入#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, a1 cannot be greater than 5, and if we buy c1 five times, we will run out of money, so a=[5,0,0].
In the second test case, a1 cannot be greater than 2, but we can buy c1 and c2 once each (buying c2 twice is not possible), so a=[2,1].
在第一个测试用例中,a1 不能大于 5;如果我们购买 c1 五次,资金将耗尽,因此 a=[5,0,0]。
在第二个测试用例中,a1 不能大于 2;但我们可各购买一次 c1 和 c2(无法购买两次 c2),因此 a=[2,1]。
输入解题思路,AI测评打分。不知道怎么写?