CF2259G.Index Removal
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An array b1,b2,…,bm is good if, for each i (1≤i<m), bi+1≥bi and bi+1−bi≤k. An array of length 1 is always good.
You are given an initially good array a1,a2,…,an. Solve the following problem for each i (1≤i≤n) independently:
- The i-th element of a is removed, making a=[a1,a2,…,ai−1,ai+1,…,an]. In one operation, you are able to subtract 1 from any element of a. What is the minimum number of operations required to make a good again?
数组 b1,b2,…,bm 被称为好数组,当且仅当对每个 i(1≤i<m),均满足 bi+1≥bi 且 bi+1−bi≤k。长度为 1 的数组恒为好数组。
给定一个初始的好数组 a1,a2,…,an。对每个 i(1≤i≤n),独立求解如下问题:
- 删除 a 的第 i 个元素,得到 a=[a1,a2,…,ai−1,ai+1,…,an]。每次操作允许将 a 中任意一个元素减 1。问:使 a 再次成为好数组所需的最少操作次数是多少?
输入格式
The first line of each input contains t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and k (2≤n≤2⋅105,1≤k≤109).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109). It is guaranteed that a is initially good.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每组输入的第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 k(2≤n≤2⋅105,1≤k≤109)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。保证初始数组 a 是“好的”。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output n space separated integers on a single line: the i-th integer denoting the solution to the problem for the i-th index.
对于每个测试用例,在一行中输出 n 个以空格分隔的整数:第 i 个整数表示该问题在第 i 个下标处的解。
输入输出样例
输入#1
7 4 2 1 2 4 5 4 1 1 2 3 4 5 7 1 8 9 16 20 5 1000000000 1 6 7 67 6767 6 1 1 1 2 2 3 4 4 1 1 2 3 3 4 2 1 2 4 6
输出#1
0 1 1 0 0 2 1 0 0 2 1 4 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 2 2 0
说明/提示
In the first test case:
- i=1, a=[2,4,5]. Since a is still good, we do not need to perform any operations.
- i=2, a=[1,4,5]. If we perform the operation once on the 2nd element, a=[1,3,5], which is a good array.
- i=3, a=[1,2,5]. If we perform the operation once on the 3rd element, a=[1,2,4], which is a good array.
- i=4, a=[1,2,4]. Since a is still good, we do not need to perform any operations.
In the fourth test case, a will remain good no matter what element we remove, so the answer for each index is 0.
在第一个测试用例中:
- i=1,a=[2,4,5]。由于 a 仍是好数组,因此无需执行任何操作。
- i=2,a=[1,4,5]。若对第 2 个元素执行一次操作,则 a=[1,3,5],这是一个好数组。
- i=3,a=[1,2,5]。若对第 3 个元素执行一次操作,则 a=[1,2,4],这是一个好数组。
- i=4,a=[1,2,4]。由于 a 仍是好数组,因此无需执行任何操作。
在第四个测试用例中,无论移除哪个元素,a 始终保持为好数组,因此每个下标对应的答案均为 0。
输入解题思路,AI测评打分。不知道怎么写?