Right Answer is here!!!(我又来了)

wurenchao 2023-10-04 15:02:24 2023-10-04 15:07:53 5 返回题目

#include<bits/stdc++.h>

using namespace std;

int a[1001];

int main(){

int n,k,cnt,ans=1;
cin>>n>>k;
for(int i=1;i<=n;++i) cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;++i){
	cnt=1;
	for(int j=i+1;a[j]-a[i]<=k&&j<=n;++j,++cnt);
	ans=max(ans,cnt);
}
cout<<ans;
return 0;

}

{{ vote && vote.total.up }}