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. [USACO13NOV]空荡荡的摊位Empty Stalls

    题目描述 Farmer John's new barn consists of a huge circle of N stalls (2 <= N <= 3,000,000), numbe ...

  2. SQL SERVER 2012 第四章 连接 JOIN の OUTER JOIN,完全连接FULL JOIN,交叉连接CROSS JOIN

    SELECT <SELECT LIST> FROM <the table you want to be the "LEFT" table> <LEFT ...

  3. 关于Chrome谷歌浏览器开发者工具网络Network中返回无数据的问题

    1.如图所示,对于有些js文件,响应中无返回数据,Failed to load response data,当然本来是应该有数据,你用火狐浏览器看,就是有的,或者直接在浏览器地址栏里输入url,也可以 ...

  4. 【Nginx】Nginx基础架构

    调用HTTP模块的流程: Worker进程会在一个for循环语句中反复调用事件模块检测网络事件.当事件模块检测到某个客户端发起的TCP请求时(接收到SYN包),将会为它建立TCP连接,成功建立连接后根 ...

  5. matlab 画图技巧

    基本画图工具:matlab 画图中线型及颜色设置 matlab中坐标轴设置技巧 **Matlab中的坐标轴设置技巧**    axisoff;      %去掉坐标轴  axistight;      ...

  6. Puppet基于Master/Agent模式实现LNMP平台部署

    前言 随着IT行业的迅猛发展,传统的运维方式靠大量人力比较吃力,运维人员面对日益增长的服务器和运维工作,不得不把很多重复的.繁琐的工作利用自动化处理.前期我们介绍了运维自动化工具ansible的简单应 ...

  7. centos7下cp -rf总是提示覆盖的解决办法

    发现每次执行cp命令,其实是执行了cp -i命令的别名,因此无论怎么输入都提示是否覆盖. cat ~/.bashrc,有“alias cp='cp -i'”,难怪如此!!! 添加#号,#alias c ...

  8. 实例 mount新硬盘方法

    0.建立挂载文件夹: mkdir /mnt/sdb1 1 .查看新硬盘: fdisk -l 2. 硬盘分区: fdisk /dev/sdb1 根据提示,依次输入 n, p, 1, 以及两次回车,然后是 ...

  9. [MAT]使用MAT比較多个heap dump文件

    使用MAT比較多个heap dump文件 调试内存泄露时,有时候适时比較2个或多个heap dump文件是非常实用的.这时须要生成多个单独的HPROF文件. 以下是一些关于怎样在MAT里比較多个hea ...

  10. Linux bash介绍与使用

    Linux————bash的简单使用 对于一个操作系统来说,shell相当于内核kernel外的一层外壳,作为用户接口.一般来说,操作系统的接口分为两类:CLI:command line interf ...