90分代码:
#include<bits/stdc++.h>
using namespace std;
int t, n, x[50005];
bool check(int m)
{
for(int i = m; i <= n; i++)
{
int st = i - m + 1;
if(x[st] >= 0 && x[i] <= t)
return true;
else if(x[i] <= 0 && abs(x[st]) <= t)
return true;
else if(x[st] <= 0 && x[i] >= 0 && min(abs(x[st]), x[i]) + (x[i] - x[st]) <= t)
return true;
}
return false;
}
int main()
{
cin >> t >> n;
for(int i = 1; i <= n; i++)
cin >> x[i];
sort(x+1, x+1+n);
int lt = 0, rt = n;
while(lt + 1 < rt)
{
int mid = (lt + rt) / 2;
if(check(mid) == true)
lt = mid;
else
rt = mid;
}
cout << lt;
return 0;
}