博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 898D Alarm Clock
阅读量:5916 次
发布时间:2019-06-19

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

Alarm Clock

time limit per test:2 seconds

memory limit per test:256 megabytes
input:standard input
output:standard output

Problem Description

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 k alarm 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 n, m and k (1 ≤ k ≤ n ≤ 2·10^5, 1 ≤ m ≤ 10^6) — number of alarm clocks, and conditions of Vitalya's waking up.

Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 10^6) 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 10^6 minutes.

Output

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

Sample Input

3 3 2

3 5 1
5 10 3
12 8 18 25 1
7 7 2
7 3 4 1 6 5 2
2 2 2
1 3

Sample Output

1

0
6
0

Hint

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.



Accepted Code

// Author : Weihao Long// Created : 2017/12/18#include 
using namespace std;int clc[200020]; // 闹钟的响铃时间数组bool stat[200020]; // 闹钟状态数组int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; ++i) { cin >> clc[i]; } sort(clc, clc + n); int pre = 0; // 当前区间的首 int now = 0; // 当前给定时间区间内响铃闹钟个数 int ans = 0; // 关掉闹钟的个数 memset(stat, false, sizeof stat); for (int i = 0; i < n; ++i) { // 当前区间的尾 ++now; while (clc[i] - clc[pre] + 1 > m) { // 区间超过给定区间 if (stat[pre] == false) { --now; } ++pre; // 区间的首后移 } if (now >= k) { // 关掉最后的闹钟 --now; stat[i] = true; ++ans; } } cout << ans << endl; return 0;}

Notes

题意:

共有 n 个闹钟,若在连续 m 分钟内,有 k 个闹钟响了,就会吵醒 Vitalya 。现在你要关掉最少数目的闹钟使 Vitalya 能够安稳地睡个觉。

思路:

从头扫到尾,每次区间的尾后移,若区间长度超过给定区间,区间的首后移。
若在给定区间内闹钟数量超过上限,就把靠后的关掉。

转载地址:http://riwvx.baihongyu.com/

你可能感兴趣的文章
oschina程序开发
查看>>
《从零开始学Swift》学习笔记(Day 40)——析构函数
查看>>
SVN Hooks的介绍及使用
查看>>
axios 拦截 , 页面跳转, token 验证(自己摸索了一天搞出来的)
查看>>
如何将经纬度利用Google Map API显示C# VS2005 Sample Code
查看>>
开发人员可以提高效率的chrome插件推荐
查看>>
性能测试分享:性能测试工具开发的案例分享(下)
查看>>
linux sar命令详解
查看>>
通过Gearman实现MySQL到Redis的数据复制
查看>>
eclipse 自动为getter和setter添加注释
查看>>
我的友情链接
查看>>
DataSet
查看>>
XMLHttpRequest - 原始AJAX初步
查看>>
有序的双链表
查看>>
mvn package时设置了maven.test.skip=true依旧执行单元测试
查看>>
Java NIO中的通道Channel(二)分散/聚集 Scatter/Gather
查看>>
四则运算
查看>>
Qt5 for Android: incompatible ABI
查看>>
zookeeper学习
查看>>
class类名的管理
查看>>