Skip to content

Instantly share code, notes, and snippets.

@j605
Created October 8, 2011 12:08
Show Gist options
  • Save j605/1272219 to your computer and use it in GitHub Desktop.
Save j605/1272219 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
long int N,K,arr[100000],i,j,ctr=0;
scanf("%d%d",&N,&K);
for(i=0;i<N;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
if(fabs(arr[i]-arr[j])==K)
ctr++;
}
}
printf("%d",ctr);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment