Problem Code: ZCO15002

Problem Link: CodeChef: Practical coding for everyone
My logic is correct but… no any test case runs successfully!
Source Code:

#include <stdio.h>
int main(void) {
	long long int n,k,a[4000],temp=0,i;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++)
	{
	    scanf("%lld",&a[i]);
	}
	for(i=0;i<n-1;i++)
	{
	    if(abs(a[i]-a[i+1])>=k)
	    {
	        temp++;
	    }
	}
	printf("%lld",temp);
	return 0;
}

The problem in your logic is that your code just checks the adjacent elements but as per problem you have to check number with each and every element of the array and then count the no. of legitimate pairs.So, code with this logic.Hope it helps… :grinning: