水太......

E. Pillars
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Marmot found a row with n pillars. The i-th pillar
has the height of hi meters.
Starting from one pillar i1,
Marmot wants to jump on the pillarsi2,
..., ik. (1 ≤ i1 < i2 < ... < ik ≤ n).
From a pillar i Marmot can jump on a pillar j only
if i < j and |hi - hj| ≥ 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.

Input

The first line contains two integers n and d (1 ≤ n ≤ 105, 0 ≤ d ≤ 109).

The second line contains n numbers h1, h2, ..., hn (1 ≤ hi ≤ 1015).

Output

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.

Sample test(s)
input
5 2
1 3 6 7 4
output
4
1 2 3 5
input
10 3
2 1 3 6 9 11 7 3 20 18
output
6
1 4 6 7 8 9
Note

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.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; typedef long long int LL; const int maxn=100100; int n,K;
LL h[maxn],sum[maxn],tr[maxn];
vector<LL> road; int main()
{
cin>>n>>K;
sum[1]=1; int maxl=1;
for(int i=1;i<=n;i++)
{
cin>>h[i];
sum[i]=1;
for(int j=max(1,i-500);j<i;j++)
{
if(abs(h[j]-h[i])>=K&&sum[j]+1>sum[i])
{
sum[i]=sum[j]+1;
tr[i]=j;
}
if(sum[i]>sum[maxl])
{
maxl=i;
}
}
}
cout<<sum[maxl]<<endl;
int T=tr[maxl];
road.push_back(maxl);
while(T)
{
road.push_back(T);
T=tr[T];
}
while(road.size())
{
cout<<road.back()<<" ";
road.pop_back();
}
return 0;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

Codeforces 474 E. Pillars的更多相关文章

  1. CodeForces 474.D Flowers

    题意: 有n朵花排成一排,小明要么吃掉连续的k朵白花,或者可以吃单个的红花. 给出一个n的区间[a, b],输出总吃花的方法数模 109+7 的值. 分析: 设d(i)表示吃i朵花的方案数. 则有如下 ...

  2. Codeforces 474 F. Ant colony

    线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes inpu ...

  3. Codeforces 474 C. Captain Marmot

    4*4*4*4暴力+点的旋转+推断正方型 C. Captain Marmot time limit per test 1 second memory limit per test 256 megaby ...

  4. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  5. Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp

    E. Pillars time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  6. codeforces round 474 pathwalks

    题目传送门http://codeforces.com/contest/960/problem/F 4月25号期中考,答应过年级组长要考年排前3的,所以25号以前我就不搞竞赛了,期中考要考好. 有很多大 ...

  7. Codeforces 474E - Pillars

    一眼看上去非常像最长不下降子序列. 然后比赛的时候对每个答案长度为k的序列,维护最后一个数的最大值和最小值. 当时不知道为什么认为从长度最长倒推至前面不会太长,于是心满意足地敲了个O(n^2).结果T ...

  8. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...

  9. 【codeforces】【比赛题解】#960 CF Round #474 (Div. 1 + Div. 2, combined)

    终于打了一场CF,不知道为什么我会去打00:05的CF比赛…… 不管怎么样,这次打的很好!拿到了Div. 2选手中的第一名,成功上紫! 以后还要再接再厉! [A]Check the string 题意 ...

随机推荐

  1. android新浪分享实例

    新浪分享比较简单,新浪有提供完整的demo. android实现新浪的分享功能,分3种分享情况: 纯文本的,带图片的,图片为本地图片(传入的是图片在手机的地址),第2种带图片的是,网络图片,图片地址为 ...

  2. selenium webdriver缺陷

    关闭  selenium webdriver缺陷 除了http://573301735.com/?p=5126讲 的,昨天又发现一个让我1个小时生不如死的问题,就是使用两个不同的配置文件来初始化dri ...

  3. python实现人人网用户数据爬取及简单分析

    这是之前做的一个小项目.这几天刚好整理了一些相关资料,顺便就在这里做一个梳理啦~ 简单来说这个项目实现了,登录人人网并爬取用户数据.并对用户数据进行分析挖掘,终于效果例如以下:1.存储人人网用户数据( ...

  4. ym——Android开发编码规范(自用)

    转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持! Android开发编码规范 目的及指导原则 目的 统一规范 Eclipse编辑环境下J ...

  5. python语言学习1——初识python

    Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. 龟叔给Python的定位是“优雅”.“明确”.“简单”,所以Python ...

  6. SE 2014年4月29日

    交换网络中有vlan1 到20个vlan,要求使用MSTP技术实现vlan的负载分担. SW2为实例1(vlan1-vlan10)的主根,SW3为备根 SW3为实例2(vlan11-vlan20)的主 ...

  7. ACM-简单题之Least Common Multiple——hdu1019

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  8. 获取编译学习笔记 (六)—— si、di,双环

    疯狂暑期学习  汇编入门学习笔记 (六)-- si.di,双重循环 參考: <汇编语言> 王爽 第7章 1. and和or指令,与[bx+idata] and和or.就不多说了. [bx+ ...

  9. 分解XML方法

    分解XML方法 1.DOM生成和解析XML 2.SAX生成和解析XML 3.DOM4J生成和解析XML 4.JDOM生成和解析XML 版权声明:本文博主原创文章.博客,未经同意不得转载.

  10. 编写高效的JavaScript

    Web前端性能优化——编写高效的JavaScript   前言 随着计算机的发展,Web富应用时代的到来,Web 2.0早已不再是用div+css高质量还原设计的时代.自Gmail网页版邮件服务的问世 ...