sir i used the following logic which was giving me correct answer on ideone but i got 94 WA here…

kindly help…

```
#include<iostream>
//#include<cstdlib>
long long int x,y,i,j,flag,other,n,p,index[100000],coordinate[100000],k;
using namespace std;
void qsort(long long int x[],int first,int last){
int pivot,j,temp,i,temp2;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(x*<=x[pivot]&&i<last)
i++;
while(x[j]>x[pivot])
j--;
if(i<j){
temp=x*;
x*=x[j];
x[j]=temp;
temp2=index*;
index*=index[j];
index[j]=temp2;
}
}
temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
temp2=index[pivot];
index[pivot]=index[j];
index[j]=temp2;
qsort(x,first,j-1);
qsort(x,j+1,last);
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k>>p;
/* if(n==1)
{
cout<<"No
```

";

exit(0);

}*/
for(i=0;i<n;i++)
{
cin>>coordinate*;

index*=i+1;

}

qsort(coordinate,0,n-1);

```
while(p--)
{
flag=0;
cin>>x>>y;
if(x<=n&&y<=n)
{
for(i=0;i<n;i++)
{
if(index*==x)
{
other=y;
for(j=i+1;(j<n)&&(coordinate[j]-coordinate[j-1]<=k);j++)
{
if(index[j]==other)
{
flag=1;
break;
}
}
if(flag==1)
break;
}
else if(index*==y)
{
other=x;
for(j=i+1;(j<n)&&(coordinate[j]-coordinate[j-1]<=k);j++)
{
if(index[j]==other)
{
flag=1;
break;
}
}
if(flag==1)
break;
}
}
if(flag==1)
cout<<"Yes
```

";

else

cout<<"No

";

}

}

return 0;

}