加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

CodeForces - 985E Pencils and Boxes

发布时间:2020-12-14 04:50:13 所属栏目:大数据 来源:网络整理
导读:? ? 可以证明的是,总是存在一种最优策略使得每个组内的权值都是连续的。 ? ? 所以排完序一遍 two pointers就好啦。 ? Discription Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world,where

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

? ? 所以排完序一遍 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?n,?k?and?d?(1?≤?k?≤?n?≤?5·105,?0?≤?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,?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<bits/stdc++.h>
#define ll long long
using 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<K;i++) can[i]=0;
	for(int i=K;i<=n;i++){
		while(a[i]-a[L+1]>D){ now-=(int)can[L],L++;}
		while(R<i-K){ R++,now+=(int)can[R];}
//		printf("%d %d %d %dn",i,R,now);
		can[i]=now>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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读