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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }
    //ABC178
    class ProgramA
    {
        public void main()
        {
            //入力
            int s = int.Parse(Console.ReadLine());
            //30以上ならYes、それ以外はNoを出力

            for (int i = 0; i < s; i++)
                Console.Write("ACL");


        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            long a = long.Parse(s[0]);
            long b = long.Parse(s[1]);
            long c = long.Parse(s[2]);
            long d = long.Parse(s[3]);
            

            if((a <= c && c <= b) || (c <= a && a <= d))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");


        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            int m = int.Parse(input[1]);

            long[] count = new long[n];

            UnionFind tree = new UnionFind();//UnionFindクラスを設定
            tree.par = new long[n];
            tree.temp = new long[n];
            tree.reset(n);

            //友だちの輪をUnion-find法で決める
            for (int i = 0; i < m; i++)
            {
                string[] input2 = Console.ReadLine().Split(' ');
                int x = int.Parse(input2[0]);
                int y = int.Parse(input2[1]);
                tree.unite(x - 1, y - 1); // xの木とyの木を併合する
            }

            for(int i = 0;i < n;i++)
                count[tree.size(i) - 1]++;

            long ans = 0;
            

            for (int i = 0; i < n; i++)
                ans += count[i] / (i + 1);

            Console.WriteLine(ans - 1);
        }

    }


    /*UnionFind法のクラス*/
    class UnionFind
    {

        public long[] par;
        public long[] temp;


        //マイナスは根を示す。
        public void reset(long n)
        {
            for (int i = 0; i < n; i++)
                par[i] = -1;
        }

        //マイナスならそれはまだ属していないので根である。そうでないならさかのぼる
        public long root(long x)
        {
            if (par[x] < 0)
                return x;
            else
                return root(par[x]);
        }

        //根の併合を行い、根には要素数を足す（マイナスの値）
        public void unite(long x, long y)
        { // xとyの木を併合
            long rx = root(x); //xの根をrx
            long ry = root(y); //yの根をry
            if (rx == ry)
                return; //xとyの根が同じ(=同じ木にある)時はそのまま
            if (par[ry] > par[rx])
            {
                long temp = ry;
                ry = rx;
                rx = temp;
            }
            par[ry] += par[rx];
            par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        }

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


        //根の元に入っている
        public long size(long x)
        {
            return -par[root(x)];
        }
    }

    class Path
    {
        public long a;
        public long b;
        public Path(long a, long b)
        {
            this.a = a;
            this.b = b;
        }
    }

    class ProgramD
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long k = long.Parse(s[1]);

            long[] a = new long[n];
            long[] b = new long[n - 1];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(Console.ReadLine());

            long count = 0;
            long max = 0;
            long temp = 0;

            for (int i = 0; i < n - 1; i++)
                b[i] = a[i + 1] - a[i];

            for (int x = 0; x < n - 1; x++)
            {
                for (int i = x; i < n - 1; i++)
                {
                    temp += b[i];
                    if (Math.Abs(temp) <= k)
                    {
                        count++;
                        temp = 0;
                    }
                }

                max = Math.Max(count, max);
                count = 0;
                if (max + x + 2 >= n)
                    break;
            }

            Console.WriteLine(max + 1);

            

        }
            
    }

    class ProgramE
    {

        public void main()
        {

        }


    }

}