为什么不能用快慢指针
// Problem:
// P1102 A-B 数对
//
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1102
// Memory Limit: 125 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<algorithm>
//#include<cstdio>
#define ll long long
#define endl '\n'
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>(b);i--)
#define N 200100 //1e6+100
using namespace std;
int n,m,a[N],cnt;
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m;
rep(i,1,n)cin>>a[i];
sort(a+1,a+n+1);
int p=1,q=1;
while(p<=n&&q<=n){
if(a[q]-a[p]>m) p++;
else if(a[q]-a[p]<m)q++;
else cnt++,p++;
}
cout<<cnt<<endl;
return 0;
}