CF474E.Pillars
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Marmot found a row with n pillars. The i-th pillar has the height of h__i meters. Starting from one pillar _i_1, Marmot wants to jump on the pillars _i_2, ..., i__k. (1 ≤ _i_1 < _i_2 < ... < i__k ≤ n). From a pillar i Marmot can jump on a pillar j only if i < j and |h__i - h__j| ≥ d, where |x| is the absolute value of the number x.
Now Marmot is asking you find out a jump sequence with maximal length and print it.
土拨鼠发现了一排共 n 根柱子。第 i 根柱子的高度为 hi 米。土拨鼠从某一根柱子 i1 出发,希望依次跳到柱子 i2,…,ik 上(满足 1≤i1<i2<⋯<ik≤n)。从柱子 i 跳到柱子 j 的条件是:i<j 且 ∣hi−hj∣≥d,其中 ∣x∣ 表示数 x 的绝对值。
现在土拨鼠请你找出一个长度最长的跳跃序列,并将其输出。
输入格式
The first line contains two integers n and d (1 ≤ n ≤ 105, 0 ≤ d ≤ 109).
The second line contains n numbers _h_1, _h_2, ..., h__n (1 ≤ h__i ≤ 1015).
第一行包含两个整数 n 和 d(1 ≤ n ≤ 105,0 ≤ d ≤ 109)。
第二行包含 n 个数 h1, h2, ..., hn(1 ≤ hi ≤ 1015)。
输出格式
The first line should contain one integer k, the maximal length of a jump sequence.
The second line should contain k integers _i_1, _i_2, ..., i__k (1 ≤ _i_1 < _i_2 < ... < i__k ≤ n), representing the pillars' indices from the maximal length jump sequence.
If there is more than one maximal length jump sequence, print any.
第一行应包含一个整数 k,表示跳跃序列的最大长度。
第二行应包含 k 个整数 i1, i2, …, ik(满足 1≤i1<i2<⋯<ik≤n),表示最长跳跃序列中各柱子的下标。
若存在多个最长跳跃序列,输出任意一个即可。
输入输出样例
输入#1
5 2 1 3 6 7 4
输出#1
4 1 2 3 5
输入#2
10 3 2 1 3 6 9 11 7 3 20 18
输出#2
6 1 4 6 7 8 9
说明/提示
In the first example Marmot chooses the pillars 1, 2, 3, 5 with the heights 1, 3, 6, 4. Another jump sequence of length 4 is 1, 2, 4, 5.
在第一个例子中,土拨鼠选择了高度分别为 1、3、6、4 的第 1、2、3、5 号柱子。另一个长度为 4 的跳跃序列为 1、2、4、5。
输入解题思路,AI测评打分。不知道怎么写?