#K50717. Message Grouping Based on Time Differences

    ID: 28927 Type: Default 1000ms 256MiB

Message Grouping Based on Time Differences

Message Grouping Based on Time Differences

You are given a series of messages, each with an integer timestamp. The timestamps are provided in non-decreasing order. Two consecutive messages are considered to belong to the same group if the difference between their timestamps does not exceed a given threshold k. Otherwise, a new group is formed.

Formally, if the messages have timestamps \(t_1, t_2, \ldots, t_n\), then a new group is initiated whenever \(t_{i+1} - t_i > k\). Your task is to determine the total number of groups formed.

Note: If no messages are provided (n = 0), the output should be 0.

inputFormat

The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the number of messages and \(k\) is the similarity threshold.

If \(n > 0\), the second line contains \(n\) space-separated integers representing the timestamps (in non-decreasing order) when the messages were sent.

outputFormat

Output a single integer representing the number of groups formed based on the given criteria.

## sample
5 2
1 2 3 4 7
2

</p>