#include<bits/stdc++.h>
using namespace std;
void solve(){
long n,k;
cin>>n>>k;
long a[n];
for(long i = 0;i < n;i++)
{
cin>>a[i];
}
sort(a,a+n);
deque<long> q;
long ans = 0;
for(long i = 0;i < n;i++)
{
q.push_back(a[i]);
while(q.back() - q.front() > k) q.pop_front();
ans = max(ans,long(q.size()));
}
cout<<ans<<endl;
}
int main(){
long t = 0,res = 0;
cin>>t;
while(t)
{
solve();
t--;
}
return 0;
}
牛客网 组队 双端队列典型题
最新推荐文章于 2023-04-05 09:56:50 发布