#C11715. Count Corrupted Elements in a Message Array
Count Corrupted Elements in a Message Array
Count Corrupted Elements in a Message Array
Given an array of integers representing a message and an integer threshold (k), determine the total count of corrupted elements. Two consecutive elements (a_i) and (a_{i+1}) are considered corrupted if (|a_i - a_{i+1}| > k). In such a case, both elements are counted as corrupted. Note that an element may be counted twice if it is involved in two different corrupted pairs. For example, if (n = 5), (k = 3), and the message is [1, 6, 4, 3, 8], then the pairs (1,6) and (3,8) are corrupted, giving a total corrupted count of 4.
inputFormat
The input is given via standard input (stdin) in two lines:
- The first line contains two integers (n) and (k), where (n) is the number of elements in the message and (k) is the threshold.
- The second line contains (n) space-separated integers representing the message.
outputFormat
Output a single integer to standard output (stdout) representing the total count of corrupted elements.## sample
4 2
10 10 10 10
0