数据范围:
1 ≤ T ≤ 100
1 ≤ n ≤ 5000
1 ≤ m ≤ 10
0 ≤ xi≤1000
#include <iostream>
using namespace std;
int main()
{
int T, max[1010], min[1010];
int a[5050];
cin >> T;
int k = T;
while (T--)
{
int m, n, temp=1,c=0;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int j = 1; j < n; j++)
{
int key = a[j];
int i = j - 1;
while (i >= 0 && a[i] > key)
{
a[i + 1] = a[i];
i--;
}
a[i + 1] = key;
}
for (int i = 0; i < n;)
{
int b = 0;
if (a[i + 1] - a[i] <= m&&a[i+1]>=0)
{
b = 1;
i++;
temp++;
continue;
}
if (b == 0)
{
i++;
c++;
if (temp < min[T] || c == 1)
{
min[T] = temp;
}
if (temp > max[T])
max[T] = temp;
temp = 1;
}
}
}
while (k--)
cout << min[k] << " " << max[k] << endl;
return 0;
}