You are given a set of points x1x1, x2x2, ..., xnxn on the number line.
Two points ii and jj can be matched with each other if the following conditions hold:
- neither ii nor jj is matched with any other point;
- |xi−xj|≥z|xi−xj|≥z.
What is the maximum number of pairs of points you can match with each other?
Input
The first line contains two integers nn and zz (2≤n≤2⋅1052≤n≤2⋅105, 1≤z≤1091≤z≤109) — the number of points and the constraint on the distance between matched points, respectively.
The second line contains nn integers x1x1, x2x2, ..., xnxn (1≤xi≤1091≤xi≤109).
Output
Print one integer — the maximum number of pairs of points you can match with each other.
Examples
Input
4 2 1 3 3 7
Output
2
Input
5 5 10 9 5 8 7
Output
1
Note
In the first example, you may match point 11 with point 22 (|3−1|≥2|3−1|≥2), and point 33 with point 44 (|7−3|≥2|7−3|≥2).
In the second example, you may match point 11 with point 33 (|5−10|≥5|5−10|≥5).
题意:就是给你一个数组,一个K,在给定区间范围,让你求区间范围里每两个数差的绝对值是否大于等于k,如果等于就++;
一开始一直t,没想到用二分,后来改了。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[210000];
bool vis[210000];
int main()
{
ll z;
ios::sync_with_stdio(false);
int n;
cin>>n>>z;
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
sort(a+1,a+n+1);
int d=0;
int l=1;
int r=(n+1)/2+1;
for(; l<=n&&r<=n; r++)
{
if((a[r]-a[l])>=z)
{
l++,d++;
}
}
cout<<d<<endl;
}