cf #451(div2) D

D. Alarm Clock

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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·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

Copy

3 3 2
3 5 1

Output

Copy

1

Input

Copy

5 10 3
12 8 18 25 1

Output

Copy

0

Input

Copy

7 7 2
7 3 4 1 6 5 2

Output

Copy

6

Input

Copy

2 2 2
1 3

Output

Copy

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.

题目链接:http://codeforces.com/contest/898/problem/D

题意: 给你n个闹钟,分别在ai分钟响。要求在任意连续的m分钟内,不能多于k个闹钟响,否则就会醒来,求关闭的最少的闹钟数,使得不会醒过来。

简单贪心即可,在m分钟内,有多于k个闹钟的话,尽量的关掉后面的闹钟,如果关掉前面的闹钟的话,后面的闹钟可能就会被再次关闭,使用队列进行模拟。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue> 
using namespace std;

const int maxn = 2e5 + 5;
int a[maxn];
int n, m, k;
queue<int> q;

int main()
{
    while(cin >> n >> m >> k)
    {
        while(!q.empty())
            q.pop();
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a+n);
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            while(!q.empty() && a[i]-q.front()>=m)
                q.pop();
            if(q.size() >= k-1)
                ans ++;
            else
                q.push(a[i]);
        }
        cout << ans << endl;
     }  
     return 0;
 } 

猜你喜欢

转载自blog.csdn.net/qq_38295645/article/details/81742170
今日推荐