鸿山洞的灯

#include
using namespace std;
int p[100001],n,dist,i,ans;
int main(void)
{
    scanf ("%d%d",&n,&dist);
    for (;i scanf ("%d",&p[i]);
    sort(p,p+n);
    for (i=1;i    if (p[i-1]!=0&&p[i+1]-p[i-1]<=dist)p[i]=0,ans++;
    else
{
        int j=i-1;
        while (p[j]==0)j--;
        if (p[i+1]-p[j]<=dist)p[i]=0,ans++;
    }
    printf ("%d",ans);
}

你可能感兴趣的:(编程)