题目链接:https://cn.vjudge.net/problem/CodeForces-898D

Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.

Vitalya will definitely wake up if during some m consecutive minutes at least kalarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.

Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.

Input

First line contains three integers nm and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.

Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.

Output

Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.

Examples

Input

3 3 2
3 5 1

Output

1

Input

5 10 3
12 8 18 25 1

Output

0

Input

7 7 2
7 3 4 1 6 5 2

Output

6

Input

2 2 2
1 3

Output

0

Note

In first example Vitalya should turn off first alarm clock which rings at minute 3.

In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.

In third example Vitalya should turn off any 6 alarm clocks.

题意:给n个时间点ai-an,表示闹钟是在这个时间点响的,m表示时间段,k表示K个闹钟,在m这个时间段里有k个闹钟响,就能把他吵醒,问,最少关了多少个闹钟,可以让他不被闹钟吵醒,

具体看代码就能理解,用到的知识点是尺取法

#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1000001;
int a[N];
int b[N];
int main()
{int n,m,k;scanf("%d%d%d",&n,&m,&k);for(int i=0; i<n; i++)scanf("%d",&a[i]);sort(a,a+n);int l,r;l=r=1;int ans=0;for(int i=0; i<n; i++){b[r]=a[i];if(r-l+1==k){if(b[r]-b[l]<m){ans++;r--;}else l++;}r++;}printf("%d\n",ans);return 0;
}

E - Alarm Clock (尺取法)相关推荐

  1. CF660C Hard Process(尺取法)

    整理的算法模板合集: ACM模板 尺取法 题目中要我们求最多改变k次后连续的1的最长长度.那么转换一下,不就是求至多包含k个0的子串的最长长度吗? 直接套用尺取法的思想,维护两端点,一旦0的个数超过k ...

  2. 【常用技巧精选】尺取法

    整理的算法模板合集: ACM模板 目录 1.反向扫描 1 找指定和的整数对 A.UVA1121 Subsequence B.POJ 3320 Jessica's Reading Problem C.l ...

  3. ACM—各种模拟 总结(字符串,尺取法,数学问题)习题汇总

    目录 一.字符串模拟 二. 高精度计算 1. 回文数(高精度,进制转换) 三.数学问题模拟 四.尺取法(双指针法) 1.都说小镇的切糕贵 (尺取法,字符串) umi和弓道 五.奇怪的模拟 x的位数=l ...

  4. 尺取法 POJ 3601 Subsequence

    题目传送门 1 /* 2 题意:求连续子序列的和不小于s的长度的最小值 3 尺取法:对数组保存一组下标(起点,终点),使用两端点得到答案 4 1. 记录前i项的总和,求[i, p)长度的最小值,用二分 ...

  5. poj2739(尺取法+质数筛)

    题意:给你一个数,问这个数能否等于一系列连续的质数的和: 解题思路:质数筛打出质数表:然后就是尺取法解决: 代码: #include<iostream> #include<algor ...

  6. 尺取法 || emmmm

    给定两个上升的数组,一个数组任取一个数,求两个数差的min 尺取法emm 也不知道对不对 #include <stdio.h> #include <stdlib.h> #def ...

  7. POJ 3320 尺取法,Hash,map标记

    1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识 ...

  8. poj_2739 尺取法

    题目大意 给定一个数字N,N可能由1个或多个连续的素数求和得到,比如41 = 2+3+5+7+11+13, 41 = 11+13+17, 41 = 41.求出对于N,所有可能的组合形式. 题目分析 先 ...

  9. poj2566Bound Found尺取法进阶(java)

    题目链接: 这个尺取法的思想挺好的,如果第一次做尺取法题,不妨看下尺取法入门题. 题目大意: 多组测试数据(0,0)截止. 每组数据输入 n,k(n数字个数,k询问次数) 下一行n个数表示序列. 接下 ...

  10. poj3320Jessica's Reading Problem—尺取法(java)

    题目链接 大意:给序列数字,找出最小子序列,包含所有的元素类型.例如 5 1 8 8 8 1 输出2,因为1 8就包含了所有元素 思路:尺取法 这个和裸的尺取优点不同的是,他需要一个map来维护判断而 ...

最新文章

  1. 三星拆分将近 董事会决定先创建控股公司
  2. love2d教程8--动画
  3. VMware虚拟机安装Linux系统(详解版)
  4. adb查看安卓设备系统Android版本
  5. 计算机是最大的一片云,计算机体系结构发展的四个时代介绍
  6. 数据建模_漫谈数据仓库之维度建模
  7. Control Web Panel 中两个严重漏洞使Linux 服务器易受RCE攻击
  8. 小团队管理核心(二)
  9. Windows 10 关闭Cortana
  10. 小程序组件页面刷新问题
  11. 机器学习(一)- feature scaling
  12. python之qrcode模块生成二维码
  13. 群晖的home和homes共享文件夹介绍
  14. BAT云平台之争:百度领先,阿里发力,腾讯落后
  15. Inno 简单使用心得记录
  16. 动态内存分配与智能指针
  17. 华为机试 HJ27 查找兄弟单词
  18. Java开发编码规范手册--码出高效、码出质量
  19. AcWing4794.健身——学习笔记
  20. linux 进程通信机制,LINUX内核进程高效通信机制研究

热门文章

  1. “二清”是电商行业在支付清算领域中普遍存在的现实状况?
  2. 天道(遥远的救世主)金句,自悟自性
  3. 单片机控制气压海拔模块BMP180之模块化编程(持续更新中)
  4. excel表格斜线_WORD圆角表格,如此惊艳
  5. Android图像处理(五)镜像、倒影、drawBitmapMesh实现旗帜飘扬效果
  6. 【win7安装composer错误】:The quot;https://getcomposer.org/download/1.6.2/composer.phar.sigquot; file cou
  7. linux 动环 源码,动环监控系统中B接口的实现
  8. ros_多消息同步回调(Synchronizer)
  9. 科研热点|发一篇SCI吃半年土?为何国际期刊版面费越来越贵?
  10. 模糊神经网络应用实例,神经网络与模糊控制