-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAIRS1.cpp
33 lines (33 loc) · 826 Bytes
/
PAIRS1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=b;i>=a;--i)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a) ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<bool> visit(100002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k,a,mid,search;
ll ans=0;
std::vector<ll> arr;
cin>>n>>k;
FOR(i,0,n){cin>>a;arr.pb(a);}
sort(arr.begin(), arr.end());
FOR(i,0,n)
{
search=arr[i]+k;
auto it=lower_bound(arr.begin(), arr.end(),search);
if(*it==search)ans++;
}
cout<<ans<<ln;
return 0;
}