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.

土拨鼠发现了一排共 nn 根柱子。第 ii 根柱子的高度为 hih_i 米。土拨鼠从某一根柱子 i1i_1 出发,希望依次跳到柱子 i2,…,iki_2, \dots, i_k 上(满足 1≤i1<i2<⋯<ik≤n1 \le i_1 < i_2 < \dots < i_k \le n)。从柱子 ii 跳到柱子 jj 的条件是:i<ji < j 且 ∣hi−hj∣≥d|h_i - h_j| \ge d,其中 ∣x∣|x| 表示数 xx 的绝对值。

现在土拨鼠请你找出一个长度最长的跳跃序列,并将其输出。

输入格式

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).

第一行包含两个整数 nn 和 dd(1 ≤ n ≤ 1051 ≤ n ≤ 10^5,0 ≤ d ≤ 1090 ≤ d ≤ 10^9)。

第二行包含 nn 个数 h1, h2, ..., hnh_1, h_2, ..., h_n(1 ≤ hi ≤ 10151 ≤ h_i ≤ 10^{15})。

输出格式

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.

第一行应包含一个整数 kk,表示跳跃序列的最大长度。

第二行应包含 kk 个整数 i1, i2, …, iki_1,\ i_2,\ \dots,\ i_k(满足 1≤i1<i2<⋯<ik≤n1\le i_1 < i_2 < \dots < i_k \le 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.

在第一个例子中,土拨鼠选择了高度分别为 11、33、66、44 的第 11、22、33、55 号柱子。另一个长度为 44 的跳跃序列为 11、22、44、55。

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

首页