Under construction

Still being built. Things may change

Smart Scale

Interview

Time limit1sMemory limit1024 MB

Summary
Given N weight measurements and a threshold D, count how many distinct customers the scale registers under the stated assignment rules.
Level

Easy3 of 10

Topics
Simulation, Binary search
Solved
No attempts yet

Problem

Martynas bought a smart scale and wants to build an app that tracks his weight. The scale is not used by him alone. Sometimes guests or friends use it, and sometimes his cat steps on it by accident.

Martynas designed an algorithm to count how many different customers use the scale. At first, nobody has used the scale. When a new measurement arrives, it is assigned to a customer by these rules:

  1. If the measurement differs from the last weight measurement of every existing customer by more than DD grams, a new customer is using the scale, and this customer is registered.
  2. Otherwise, the measurement is assigned to the customer whose last weight measurement is closest to it.
  3. If several customers satisfy condition (2), the measurement is assigned to the customer whose last weight measurement is smaller.

For example, suppose the scale recorded these measurements in order:

  1. 75000 grams: Martynas weighed himself in the morning.
  2. 75500 grams: Martynas weighed himself in the evening.
  3. 3000 grams: The cat stepped on the scale.
  4. 78500 grams: Martynas's friend tried the scale.
  5. 2950 grams: The cat stepped on the scale again.
  6. 77000 grams: Martynas weighed himself again after eating.

With D=1500D = 1500, Martynas's algorithm correctly identifies three customers who used the scale.

You are given NN weight measurements recorded by the smart scale and the parameter DD. Using Martynas's algorithm, count how many different customers (people, cats, mice, and so on) used the scale.

Input

The first line contains integers NN and DD. The next NN lines each contain one weight measurement mim_i in grams.

Output

Print one integer: the number of customers who used the smart scale.

Constraints

1≤N≤10 0001 \le N \le 10\,000

0<D,mi≤200 0000 < D, m_i \le 200\,000

Examples2

  1. Example 1

    Input
    6 1500
    75000
    75500
    3000
    78500
    2950
    77000
    
    Expected output
    3
    
  2. Example 2

    Input
    8 2000
    60000
    61000
    79000
    62000
    81000
    60000
    59000
    80000
    
    Expected output
    2