博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 985E Pencils and Boxes
阅读量:4971 次
发布时间:2019-06-12

本文共 2567 字,大约阅读时间需要 8 分钟。

    可以证明的是,总是存在一种最优策略使得每个组内的权值都是连续的。

    所以排完序一遍 two pointers就好啦。

 

Discription

Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of ninteger numbers — saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:

  • Each pencil belongs to exactly one box;
  • Each non-empty box has at least k pencils in it;
  • If pencils i and j belong to the same box, then |ai - aj| ≤ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils iand j such that |ai - aj| ≤ d and they belong to different boxes.

Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO".

Input

The first line contains three integer numbers nk and d (1 ≤ k ≤ n ≤ 5·1050 ≤ d ≤ 109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — saturation of color of each pencil.

Output

Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO".

Examples

Input
6 3 10 7 2 7 7 4 2
Output
YES
Input
6 2 3 4 5 3 13 4 10
Output
YES
Input
3 2 5 10 16 22
Output
NO

Note

In the first example it is possible to distribute pencils into 2 boxes with 3pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.

In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.

 

#include
#define ll long longusing namespace std;const int maxn=500005;int n,a[maxn],K,D,now,L,R;bool can[maxn];inline int read(){ int x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()); for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; return x;}inline void solve(){ L=R=0,can[0]=now=1; for(int i=1;i
D){ now-=(int)can[L],L++;} while(R
0?1:0; }}int main(){ n=read(),K=read(),D=read(); for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+n+1); solve(); puts(can[n]?"YES":"NO"); return 0;}

  

转载于:https://www.cnblogs.com/JYYHH/p/9071227.html

你可能感兴趣的文章
scanf和gets
查看>>
highcharts 图表实例
查看>>
ubuntu下如何查看用户登录及系统授权相关信息
查看>>
秋季学期学习总结
查看>>
SpringBoot 优化内嵌的Tomcat
查看>>
【LaTeX】E喵的LaTeX新手入门教程(1)准备篇
查看>>
highcharts曲线图
查看>>
extjs动态改变样式
查看>>
PL/SQL Developer 查询的数据有乱码或者where 字段名=字段值 查不出来数据
查看>>
宏定义
查看>>
笔记:git基本操作
查看>>
生成php所需要的APNS Service pem证书的步骤
查看>>
JavaWeb之JSON
查看>>
HOT SUMMER 每天都是不一样,积极的去感受生活 C#关闭IE相应的窗口 .
查看>>
windows平台上编译mongdb-cxx-driver
查看>>
optionMenu-普通菜单使用
查看>>
2016-2017-2点集拓扑作业[本科生上课时]讲解视频
查看>>
GNU/Linux超级本ZaReason Ultralap 440体验
查看>>
将github上托管的代码 在我的域名下运行
查看>>
【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize
查看>>