CF1870D.Prefix Purchase
普及/提高-
通过率:0%
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 .
输入格式
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 .
输出格式
For each test case, output n integers a1,a2,…,an — the lexicographically largest array a that can be obtained.
输入输出样例
输入#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] .