Rikka with Competition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 772    Accepted Submission(s): 588

Problem Description

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

A wrestling match will be held tomorrow. n players will take part in it. The ith player’s strength point is ai.

If there is a match between the ith player plays and the jth player, the result will be related to |ai−aj|. If |ai−aj|>K, the player with the higher strength point will win. Otherwise each player will have a chance to win.

The competition rules is a little strange. Each time, the referee will choose two players from all remaining players randomly and hold a match between them. The loser will be be eliminated. After n−1 matches, the last player will be the winner.

Now, Yuta shows the numbers n,K and the array a and he wants to know how many players have a chance to win the competition.

It is too difficult for Rikka. Can you help her?

 

Input

The first line contains a number t(1≤t≤100), the number of the testcases. And there are no more than 2 testcases with n>1000.

For each testcase, the first line contains two numbers n,K(1≤n≤105,0≤K<109).

The second line contains n numbers ai(1≤ai≤109).

 

Output

For each testcase, print a single line with a single number -- the answer.
 

Sample Input

2
5 3
1 5 9 6 3
5 2
1 5 9 6 3
 

Sample Output

5
1
 

Source

 
 //2017-09-22
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int n, arr[N], k; int main()
{
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &k);
for(int i = ; i < n; i++){
scanf("%d", &arr[i]);
}
sort(arr, arr+n);
int ptr = n-, ans = ;
while(ptr >= && arr[ptr]-arr[ptr-] <= k){
ptr--;
ans++;
}
printf("%d\n", ans+);
} return ;
}

HDU6095的更多相关文章

  1. 2017 Multi-University Training Contest - Team 5——HDU6095&&HDU6090&&HDU

    HDU6095——Rikka with Competition 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6095 题目意思:抱歉虽然是签到题,现场 ...

  2. 【多校联合】(HDU6095)Rikka with Competition

    题意:给定$n$个数,代表$n$个选手的能量高低,现在再给一个$k$,任意在$n$个选手中挑取两个选手比赛,如果$|a_i−a_j|>K$,那么能量高的选手获胜,另一个将被淘汰,否则两个人都有机 ...

  3. 2017多校Round5(hdu6085~hdu6095)

    补题进度:7/11 1001(模意义下的卷积) 题意: 给出长度<=50000的两个数组A[] B[],保证数组中的值<=50000且A[]中数字两两不同,B[]中数字两两不同 有5000 ...

随机推荐

  1. Autofac与AOP功能例子

    using Autofac.Extras.DynamicProxy; using System; using System.Collections.Generic; using System.Linq ...

  2. while循环 格式化输出 密码本 编码的初识

    第二天课程整理 while 循环 why : while ' 循环' 的意思 what : while 无限循环 how : 1.基本结构 while + 条件 循环的代码 初识循环 while tr ...

  3. 教你用python打造WiFiddos

    本文来源于i春秋学院,未经允许严禁转载. 0x00 前言因为在百度上很难找到有关于用python打造WiFidos的工具的,而且不希望大家成为一名脚本小子,所以我打算写一篇,需要的工具有scapy,i ...

  4. OkHttp 入门篇

    OkHttp是一个HTTP & HTTP2的客户端,能够用来进行Android 和 Java 开发. HTTP是现代应用的最基本的网络环境.让你的HTTP更加有效的工作能够让你的东西加载更快而 ...

  5. 一种基于python的人脸识别开源系统

    今天在搜索人脸识别的文章时,无意中搜到一个比较开源代码,介绍说是这个系统人脸的识别率 是比较高的,可以达到:99.38%.这么高的识别率,着实把我吓了一跳.抱着实事求是的态度.个人 就做了一些验证和研 ...

  6. LeetCode:104_Maximum Depth of Binary Tree | 二叉树的最大深度 | Easy

    要求:求二叉树的深度(二叉树的深度为最远叶子节点到根节点的距离,即根节点到最远叶子节点的距离) Given a binary tree, find its maximum depth. The max ...

  7. Python--DBUtil

    Python--DBUtil包 1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DB ...

  8. js学习笔记----JavaScript中DOM扩展的那些事

    什么都不说,先上总结的图~   Selectors API(选择符API) querySelector()方法 接收一个css选择符,返回与该模式匹配的第一个元素,如果没有找到匹配的元素,返回null ...

  9. Python内置类型(5)--迭代器类型

    指能够被内置函数next调用并不断返回下一个值,直到最后抛出StopIteration错误表示无法继续返回下一个值的对象称为迭代器(Iterator) 其实以上的说法只是侠义上的迭代器的定义,在pyt ...

  10. Java 中三大构建工具:Ant、Maven和Gradle

    Java世界中主要有三大构建工具:Ant.Maven和Gradle 目前:Ant已经销声匿迹.Maven也没落了,而Gradle的发展则如日中天. Maven的主要功能主要分为5点,分别是依赖管理系统 ...