407773: GYM102892 2 Egocentric Subarrays

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

2. Egocentric Subarraystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have an array $$$a$$$ consisting of $$$n$$$ positive integers, and an integer $$$k$$$.

You call a subarray an egocentric subarray if the difference between the maximum and minimum elements of the subarray is equal to $$$k$$$.

Recall that a subarray is a contiguous segment of elements of the original array, in order.

For example, if $$$a = [5, 4, 1, 2, 3, 6]$$$ and $$$k = 3$$$, then $$$[4, 1]$$$, $$$[4, 1, 2, 3]$$$, and $$$[3, 6]$$$ are egocentric subarrays, while $$$[5, 4, 1, 2]$$$, $$$[4, 1, 2, 3, 6]$$$, and $$$[5]$$$ are not.

Your task is to find the number of egocentric subarrays in the array.

Input

The first line of input contains two space-separated integers $$$n$$$ $$$(1 <= n <= 100)$$$ and $$$k$$$ $$$(1 <= k <= 10^9)$$$: the length of the array, and the number to find if the difference is equal to, respectively.

The next line consists of $$$n$$$ space-separated integers: the array elements $$$(1 <= a_i <= 10^9)$$$.

Output

Output the number of egocentric subarrays of the array.

Scoring

Full problem: 7 points

ExamplesInput
5 3
5 4 1 2 3
Output
3
Input
11 7
1 3 7 6 4 2 11 18 12 9 1
Output
2
Note

In the first example, $$$[4, 1]$$$, $$$[4, 1, 2]$$$, and $$$[4, 1, 2, 3]$$$ are egocentric subarrays.

In the second example, $$$[11, 18]$$$ and $$$[11, 18, 12]$$$ are egocentric subarrays.

加入题单

上一题 下一题 算法标签: