P1102 A-B数对
用map过掉,可以当高效的桶排用,map<long long,int>m;
意思是m[long long]==int;
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.13
using namespace std;
long long n,c,ans;
long long a[];
map<long long,int>m;
void in(long long &x)
{
long long y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=x*+c-'',c=g();
x*=y;
}
void o(long long x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} long long find(long long x)
{
long long l=x,r=n,mid;
while(l<r)
{
mid=(l+r)>>;
if(a[mid]>=a[x]+c)
r=mid;
else
l=mid+;
}
return l-;
} int main()
{
in(n),in(c);
For(i,,n)
in(a[i]),m[a[i]]++;
sort(a+,a+n+);
For(i,,n)
ans+=m[a[i]-c];
o(ans);
return ;
}