K difference Subsequence

3

2 votes
Medium
Problem

You are given an array of N integers. Your task is to find the number of ways of selecting non-empty subsequences of the array such that the absolute difference between any two adjacent elements (if they exist ) of the selected subsequence is not greater than K.

Since, the number of ways can be very large, output it modulo 1000000007.

Note:subsequence of an array is an ordered subset of the array's elements having the same sequential ordering as the original array.

INPUT FORMAT

  • First line of input contains two space separated integers N and K.
  • Second line of input contains N space separated integers denoting the N elements of the array.

OUTPUT FORMAT

  • Output the number of ways of selecting subsequences following the given condition, modulo 1000000007.

CONSTRAINTS

  • 1 ≤ N ≤ 500000
  • 0 ≤ K ≤ 109
  • -109 ≤ A[i] ≤ 109 , A[i] denotes the ith element of the array.
Sample Input
5 2
2 4 0 3 -1
Sample Output
12
Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?