【2017 Multi-University Training Contest - Team 5】Rikka with Competition
把所有人的能力从大到小排;
能力最大的肯定可能拿冠军;
然后一个一个地往后扫描;
一旦出现a[i-1]-a[i]>k;
则说明从这以后的人,都不可能再和有实力拿冠军的人竞争了
无论怎么安排都赢不了那部分可能拿冠军的人.
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;
int n,k,a[N+100];
int main(){
//Open();
//Close();
int T;
ri(T);
while (T--){
ri(n),ri(k);
rep1(i,1,n) ri(a[i]);
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
int now = 1;
rep1(i,2,n){
if (a[i-1]-a[i] > k){
break;
}
now++;
}
oi(now);puts("");
}
return 0;
}