C. Match Points(二分答案)

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

Copy

4 2
1 3 3 7

output

Copy

2

input

Copy

5 5
10 9 5 8 7

output

Copy

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).

#include<bits/stdc++.h>
using namespace std;
int a[200020];
int n,z;
int ok(int x)
{
    for(int i=0; i<x; i++)
    {
        if(a[n-x+i]-a[i]<z)
            return 0;
    }
    return 1;
}
int main()
{
    cin>>n>>z;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    int l=1,r=n/2,ans=0;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(ok(mid))
            ans=mid,l=mid+1;
        else
            r=mid-1;
    }
    cout<<ans<<endl;
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章