Solution to the problem number 346 of AceptaelReto - 346.

Any questions do not hesitate to contact.

#include <bits/stdc++.h>
#define INF 0x3F3F3F3F
using namespace std;

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)==2 && (n!=0||m!=0))
    {
       int arr[n];
       int res = 1,cnt = 0,actual=0;
       for(int i=0; i<n;i++) scanf("%d",&arr[i]);
       for(int i=0; i<n;i++)
       {
           for(int j=i; j<n;j++)
           {
               if(abs(arr[actual]-arr[j])<m)
               {
               cnt++;
               res = max (res,cnt);
               i=j;
               }
               else
               {
                 cnt--;
                 actual++;
                 i=j-1;
                 break;
               }
           }
       }
       printf("%d\n",res);
    }
    return 0;
}

Don't miss anything.

Keep in touch with Isaac Lozano Osorio!