1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <cstdlib> #include <algorithm> #include <cstring> #include <cctype> #define INF 2000000000 using namespace std; typedef long long ll; int a[100005],n,k,b[100005]={0}; int (){ int f=1,x=0;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();} while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar(); return f*x; } void init(){ n=read(),k=read(); for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+n+1); } void solve(){ int lst=0,ans=0,maxi=0; for(int i=1;i<=n;i++){ int loc=lower_bound(a+1,a+n+1,a[i]+k+1)-a-i; b[i]=loc; while(lst+b[lst+1]<i) lst++,maxi=max(maxi,b[lst]); ans=max(ans,maxi+loc); } printf("%dn",ans); } int main(){ init(); solve(); return 0; }
|
近期评论