codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

898D.md (2167B)


      1 Source: https://codeforces.com/problemset/problem/898/D
      2 
      3 D. Alarm Clock
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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 *a**i* — 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 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.
     30 
     31 Second line contains sequence of distinct integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 106) in which *a**i* 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.
     32 
     33 Output
     34 
     35 Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3 3 2  
     43 3 5 1
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 1
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 5 10 3  
     56 12 8 18 25 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 0
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 7 7 2  
     69 7 3 4 1 6 5 2
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 6
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 2 2 2  
     82 1 3
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 0
     89 ```
     90 
     91 Note
     92 
     93 In first example Vitalya should turn off first alarm clock which rings at minute 3.
     94 
     95 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.
     96 
     97 In third example Vitalya should turn off any 6 alarm clocks.