# Codeforces Round #667 (Div. 3) E. Two Platforms

（原题面可谓花里胡哨）

/*
* Author	: GhostCai
* Date		: 2020.09.04
* Time		: 22:47:38

Expecto Patronum

*/

#include<bits/stdc++.h>

using namespace std;

inline int rd(){
int ret=0,f=1;char c;
while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
while(isdigit(c))ret=ret*10+c-'0',c=getchar();
return ret*f;
}

#define pc putchar
#define space() pc(' ')
#define nextline() pc('\n')
void pot(int x){if(!x)return;pot(x/10);pc('0'+x%10);}
void out(int x){if(!x)pc('0');if(x<0)pc('-'),x=-x;pot(x);}

const int MAXN = 200005;

int x[MAXN];

int solve(){
int n,len;
n=rd();len=rd();
for(int i=1;i<=n;i++)x[i]=rd();
for(int i=1;i<=n;i++) rd();//useless though
sort(x+1,x+1+n);
int ans=0,premax=0;
for(int i=1,j=1,k=1;i<=n;i++){
while(x[i]+len>=x[j]&&j<n) j++;
if(x[i]+len<x[j])j--;
while(i-1&&x[k]<x[i-1]-len&&k<i-1) k++;
premax=max(premax,(i-1)-k+1);
ans=max(ans,premax+j-i+1);
}
return ans;
}

int main(){
int T=rd();
while(T--) cout<<solve()<<endl;
return 0;
}

posted @ 2020-09-06 17:54  GhostCai  阅读(126)  评论(0编辑  收藏  举报