C Match Points (二分) ( Educational Codeforces Round 64 (Rated for Div. 2) )

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;
  • |xixj|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 (2n21052≤n≤2⋅105, 1z1091≤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 (1xi1091≤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 (|31|2|3−1|≥2), and point 33with point 44 (|73|2|7−3|≥2).

In the second example, you may match point 11 with point 33 (|510|5|5−10|≥5).

 

 

#include 
#include 
#include 
#include <string>
#include 
#include 
#include 
#include 
#include <set>
#include 
#include 
#include 
//
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
//
#define fi      first
#define se      second
#define pb      push_back
#define pq      priority_queue
#define ok      return 0;
#define os(str) cout<#define gcd __gcd
#define mem(s,t) memset(s,t,sizeof(s))
#define debug(a,n) for(int i=0;i#define debug1(a,n) for(int i=1;i<=n;i++) cout<#define debug02(a,n,m) for(int i=0;i#define read11(a,k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i];}
#define read02(a,n,m) for(int i=0;i>a[i][j] ; }
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);

using namespace std;
inline void NO()
{
    cout<<"NO"<<endl;
}
inline void YES()
{
    cout<<"YES"<<endl;
}
const  int  mxn = 2e5+10;
#define oi(x)   cout<#define rep(k)    for (int i=0;i#define rep1(j,k) for (int i=j;i<=k;  i++)
#define per(j,k)  for (int i=j;i>=k; i--)
//#define per(k)    for (int i=k-1;i>=0;i--)
#define lli long long
string str,ch;
lli a[mxn],vis[mxn];
int n,k,ans;
int judge(int mid)
{
    for(int i=n-mid ,j=0; i)
    {
        if(a[i]-a[j]<k)
        {
            return 0;
        }
        else
            j++;
    }
    ans = mid;
    return 1;
}
int main()
{
    while(cin>>n>>k)
    {
        ans = 0;
        for(int i=0;i>a[i];
        sort(a,a+n);
        int l = 0 ,r = n/2 , mid;
        while(l<=r)
        {
            mid = l + ( (r-l)>>1  );
            //cout<<"        +++     "<
            if(judge(mid))
                l = mid +1 ;
            else
                r = mid - 1;

        }
        cout<endl;
    }
    ok;
}

 

你可能感兴趣的:(C Match Points (二分) ( Educational Codeforces Round 64 (Rated for Div. 2) ))