1 条题解

  • 0
    @ 2023-7-19 21:59:40

    暴力模拟

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<algorithm>
    #define int long long
    #define ull unsigned long long
    using namespace std;
    const int N=1e7+5;
    const int M=2e6+5;
    const int INF=0x3f3f3f3f;
    inline int read(){
    	int x=0,f=1;char ch=getchar();
    	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
    	return x*f;
    }
    int n,a[N],k;
    signed main(){
    	n=read();
    	k=read();
    	for(int i=1;i<=n;i++){
    		a[i]=read();
    	}
    	sort(a+1,a+1+n);
    	int mt=a[1],times=1;
    	for(int i=1;i<=n;i++){
    		
    		if(a[i]-mt>k){
    			mt=a[i];
    			times++;
    		}
    		//cout << a[i] << " " << mt << " " << times << endl;
    	}
    	cout << times;
    	return 0;
    }
    
    
    • 1

    信息

    ID
    1585
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    9
    已通过
    2
    上传者