A9588 | Pillars
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
Now Marmot is asking you find out a jump sequence with maximal length and print it.
输入格式
The first line contains two integers n and d (1 ≤ n ≤ 10^5, 0 ≤ d ≤ 10^9).
The second line contains n numbers h1, h2, ..., hn (1 ≤ hi ≤ 10^15).
The second line contains n numbers h1, h2, ..., hn (1 ≤ hi ≤ 10^15).
输出格式
The first line should contain one integer k, the maximal length of a jump sequence.
The second line should contain k integers i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n), representing the pillars' indices from the maximal length jump sequence.
If there is more than one maximal length jump sequence, print any.
The second line should contain k integers i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n), representing the pillars' indices from the maximal length jump sequence.
If there is more than one maximal length jump sequence, print any.
输入输出样例
输入 #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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted