It doesn't matter whether the array is sorted or not, we can do it in O(n) (linear time) time. Use hashing.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int arr[n];
map<int,int>mp; // for hashing ()
for(int i=0;i<n;i++)
cin >>arr[i];
for(int i=0;i<n;i++) // O(n)
{
if(mp[arr[i]-k] || mp[arr[i]+k])
{
cout<<"Present"<<endl;
break;
}
mp[arr[i]]=1;
}
return 0;
}