Problem:
Score : 400 points

Problem Statement

You are given a sequence A_1, A_2, ..., A_N and an integer K.

Print the maximum possible length of a sequence B that satisfies the following conditions:

B is a (not necessarily continuous) subsequence of A.

For each pair of adjacents elements of B, the absolute difference of the elements is at most K.

Constraints

1 \leq N \leq 300,000

0 \leq A_i \leq 300,000

0 \leq K \leq 300,000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1
A_2
:
A_N

Output

Print the answer.

Sample Input 1

10 3
1
5
4
3
8
6
9
7
2
4

Sample Output 1

7

For example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.

It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).

All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3.

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(llint i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
const ll mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = 1000000000;

class UnionFind {
public:
	//親の番号を格納する
	vector<int> par;

	//最初は全てが根であるとして初期化
	UnionFind(int N) {
		par.resize(N);
		for (int i = 0; i < N; i++)par[i] = i;
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (par[A] == A) return A;
		return par[A] = root(par[A]);
	}


	//AとBをくっ付ける
	bool unite(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//Bの親をAに変更する
		par[B] = A;

		return true;
	}
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n,k;
	cin >> n >> k;
	hei(int) a(n),s(n-1);
	rep(i, 0, n)cin >> a[i];
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	rep(i, 0, n - 1) {
		s[i] = abs(a[i + 1] - a[i]);
	}
	int ans = n;
	int x = a[0];
	rep(i, 0, n - 1) {
		if (s[i] > k) {
			if (i == n - 2) {
				ans--;
				break;
			}
			ans--;
			s[i+1] = abs(a[i + 2]-x);
		}
		else {
			x = a[i + 1];
		}
	}
	cout << ans << endl;
	
	return 0;
}