比赛
题目背景:
分析:暴力
将数据从小到大排序,从大到小找到第一个满足a[i] + k < a[i + 1]的位置,那么答案就是n - i了,如果找不到那么就是n了·····注意边界
Source:
/*
created by scarlyw
*/
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
const int MAXN = 100000 + 10;
int n, ans, k, t;
int a[MAXN];
inline void solve() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
std::sort(a + 1, a + n + 1), ans = 1;
for (int i = n - 1; i >= 1; --i)
if (a[i + 1] - a[i] > k) break ;
else ans++;
std::cout << ans << '\n';
}
int main() {
// freopen("pk.in", "r", stdin);
// freopen("pk.out", "w", stdout);
scanf("%d", &t);
while (t--) solve();
return 0;
}