B. Strip
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.

Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:

  • Each piece should contain at least l numbers.
  • The difference between the maximal and the minimal number on the piece should be at most s.

Please help Alexandra to find the minimal number of pieces meeting the condition above.

Input

The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).

The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).

Output

Output the minimal number of strip pieces.

If there are no ways to split the strip, output -1.

Examples
Input
7 2 2
1 3 1 2 4 1 2
Output
3
Input
7 2 2
1 100 1 100 1 100 1
Output
-1
Note

For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2].

For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.

我先说几句 我*************

不到四十行的sbdp写了两天。。。。。。。到现在还没想懂

不说了泪奔

#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
#define N 200010
#define inf 1000000009
int n,S,l,last=;
int dp[N],mn[*N],a[N];
multiset<int> s;
set<int> v;
void update(int l,int r,int x,int pos,int num)
{
if(l==r)
{
mn[x]=num;
return;
}
int mid=(l+r)>>;
if(pos<=mid) update(l,mid,x<<,pos,num);
else update(mid+,r,x<<|,pos,num);
mn[x]=min(mn[x<<],mn[x<<|]);
}
int query(int l,int r,int x,int a,int b)
{
if(l>b||r<a) return inf;
if(l>=a&&r<=b) return mn[x];
int mid=(l+r)>>;
return min(query(l,mid,x<<,a,b),query(mid+,r,x<<|,a,b));
}
int main()
{
memset(mn,0x3f3f,sizeof(mn));
scanf("%d%d%d",&n,&S,&l);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
/*
dp[i]:到i位置能分多少段
*/
for(int i=;i<=n;i++)
{
s.insert(a[i]);
while(*s.rbegin()-*s.begin()>S)
{
s.erase(s.find(a[last]));
last++;
}
if(i-last+>=l&&last==) dp[i]=; else
dp[i]=query(,n,,last-,i-l)+;
update(,n,,i,dp[i]);
}
printf("%d\n",dp[n]>=inf?-:dp[n]);
return ;
}

Strip的更多相关文章

  1. python strip()函数 介绍

    python strip()函数 介绍,需要的朋友可以参考一下   函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm)        删除s字符串中开头.结尾处,位于 rm删除 ...

  2. 4、Python:strip(),split()

    1.strip()函数 strip()是删除'()'里面的字符,当()为空时,默认删除空白符(包括'\n','\r','\t','') (1)s.strip(rm)        删除s字符串中开头. ...

  3. Strip JS – 低侵入,响应式的 Lightbox 效果

    Strip  是一个灯箱效果插件,显示的时候只会覆盖部分的页面,这使得侵扰程度较低,并留出了空间与页面上的大屏幕,同时给予小型移动设备上的经典灯箱体验.Strp JS 基于 jQuery 库实现,支持 ...

  4. strip的用法

    函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm)        删除s字符串中开头.结尾处,位于 rm删除序列的字符 s.lstrip(rm)       删除s字符串中开头 ...

  5. python中strip,lstrip,rstrip简介

    一.起因 今天在做角色控制中,有一个地方用到rstrip,判断用户请求的url是否与数据库对应可用权限中url相符. if request.path == x.url or request.path. ...

  6. 【C++实现python字符串函数库】strip、lstrip、rstrip方法

    [C++实现python字符串函数库]strip.lstrip.rstrip方法 这三个方法用于删除字符串首尾处指定的字符,默认删除空白符(包括'\n', '\r', '\t', ' '). s.st ...

  7. pythong中字符串strip的用法

    strip的用法是去除字符串中前后两端的xx字符,xx是一个字符数组,并不是去掉“”中的字符串, 数组中包含的字符都要在字符串中去除.默认去掉空格,lstrip则是去掉左边的,rstrip是右边的 见 ...

  8. Python strip函数用法小结

    声明:s为字符串,rm为要删除的字符序列 s.strip(rm)        删除s字符串中开头.结尾处,位于 rm删除序列的字符 s.lstrip(rm)       删除s字符串中开头处,位于 ...

  9. python strip() lstrip() rstrip() 使用方法

    Python中的strip用于去除字符串的首尾字符串,同理,lstrip用于去除最左边的字符,rstrip用于去除最右边的字符. 这三个函数都可传入一个参数,指定要去除的首尾字符. 需要注意的是,传入 ...

  10. Linux Strip

    一.简介 strip经常用来去除目标文件中的一些符号表.调试符号表信息,以减小程序的大小. 二.语法 https://sourceware.org/binutils/docs/binutils/str ...

随机推荐

  1. vagrant的学习 之 打包分发

    vagrant的学习 之 打包分发 一.打包Box: (1)关闭虚拟机. vagrant halt (2)打包: vagrant package 这样打包出来的文件叫package.box. 指定生成 ...

  2. Python闭包函数

    闭包 闭包:python中的闭包从表现形式上定义(解释)为: 如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure). 先看一个函数: ...

  3. Django学习之 - 基础视图函数

    视图:Views 获取用户请求的方法: 1: request.GET 2: request.POST 3: request.FILES # checkbox 等多选文件 4:request.POST. ...

  4. Codeforces 549C(博弈)

    C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. CF723E(欧拉回路)

    题意: 给出一个有向图,要求给每条边重定向,使得定向后出度等于入度的点最多,输出答案和任意一种方案. 分析: 将图看作无向图,对每条边重定向 首先我们肯定分成多个连通分量来考虑,每一个连通分量都是一个 ...

  6. Spring AOP Capability and Goal

    AOP Capability: 1.Spring声明式事务管理配置. 2.Controller层的参数校验. 3.使用Spring AOP实现MySQL数据库读写分离案例分析 4.在执行方法前,判断是 ...

  7. struts2 动态工作流

    话不多说,直接贴代码: public class TestAction { private String nextPage;//保存下一步内容的属性 public String destroy(){ ...

  8. sendEmail实现邮件报警发送

    安装wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz tar -xf sendEmail-v ...

  9. django 简易博客开发 2 模板和数据查询

    首先还是贴一下项目地址  https://github.com/goodspeedcheng/sblog   因为代码全在上面 上一篇博客我们介绍了 django的安装配置,新建project,新建a ...

  10. 【scrapy】Item Pipeline

    After an item has been scraped by a spider,it is sent to the Item Pipeline which process it through ...