把做过的题写一写吧,还可以用lower_bound,upper_bound优化的
//160K 0MS
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a[1005];
int main(){
int r, n;
while(scanf("%d %d", &r, &n) != EOF){
if(r == -1 && n == -1) break;
for(int i=1; i<=n; i++)
scanf("%d", &a[i]);
sort(a+1, a+n+1);
int cur = 1, res = 0, center = 1;
while(cur <= n){
while(a[center]-r <= a[cur] && center <= n) center++; //不带等号就跪了
center--;
res++;
while(a[cur] <= a[center]+r && cur <= n) cur++; //不带等号就跪了
}
printf("%d\n", res);
}
return 0;
}