2017-09-22 22:01:19

writer:pprp

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. nn players will take part in it. The iith player’s strength point is aiai.

If there is a match between the iith player plays and the jjth player, the result will be related to |ai−aj||ai−aj|. If |ai−aj|>K|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−1n−1 matches, the last player will be the winner.

Now, Yuta shows the numbers n,Kn,K and the array aa 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?

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

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

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

OutputFor 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

代码如下:

#include <iostream>
#include <algorithm> using namespace std;
const int maxn = ;
int arr[maxn]; int main()
{
int cas;
cin >> cas;
while(cas--)
{
int n, k;
cin >> n >> k;
int ans = ;
for(int i = ; i < n ; i++)
{
cin >> arr[i];
}
sort(arr,arr+n);
for(int i = n-; i > ; i--)
{
if(arr[i]-arr[i-] > k)
break;
ans++;
}
cout << ans << endl;
} return ;
}

2017 beijing icpc E - Rikka with Competition的更多相关文章

  1. 2017 beijing icpc A - Euler theorem

    2017-09-22 21:59:43 writer:pprp HazelFan is given two positive integers a,ba,b, and he wants to calc ...

  2. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  3. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  4. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  5. 2017 多校5 Rikka with String

    2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...

  6. 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  7. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  8. 记2017青岛ICPC

    2017青岛ICPC 11月4日 早上很早到达了青岛,然后去报道,走了好久的校园,穿的很少冷得瑟瑟发抖.中午教练请吃大餐,吃完饭就去热身赛了. 开幕式的时候,教练作为教练代表讲话,感觉周围的队伍看过来 ...

  9. 记2017沈阳ICPC

    2017沈阳ICPC 10月20日 早上十点抵达沈阳,趁着老师还没到,跑去故宫游玩了一下,玩到一点多回到宾馆,顺便吃了群里大佬说很好吃的喜家德虾饺(真的好好吃),回到宾馆后身体有点不舒服了,头晕晕的, ...

随机推荐

  1. 启动tomcat时为tomcat指定JDK

    背景:服务器环境:JDK1.7,Tomcat8 需求: 需要在Tomcat8部署项目,该项目需要运行在JDK1.8 将Tomcat8和JDK1.8上传至服务器,然后解压在指定目录下. 为tomcat指 ...

  2. java.util.Calendar

    package day14; import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; import java.util.Cal ...

  3. JavaWeb—Base64编码(转载)

    基本概念 Base64这个术语最初是在“MIME内容传输编码规范”中提出的.Base64不是一种加密算法,虽然编码后的字符串看起来有点加密的赶脚.它实际上是一种“二进制到文本”的编码方法,它能够将给定 ...

  4. 19.如何在vue里面调用其他js

    可以通过把js放到服务器,然后再html文件中通过链接的形式引入,这是目前我试过成功的唯一方法

  5. Spring第二弹—–搭建与测试Spring的开发环境

    PS:Spring既可以使用在javaSE中,也可以使用在javaWeb中. 使用Spring需要的jar 下载spring(我下载的是2.5.6版本),然后进行解压缩,在解压目录中找到下面jar文件 ...

  6. 在eclipse添加第一次添加Python项目时,提示: Project interpreter not specified

    按图片操作,添加Python的路径,就能解决该问题

  7. Linux系统下RPM命令和yum的使用

    Linux系统下RPM命令和yum的使用 RPM:Redhat Packages Manager (红帽系列软件包的管理),主要用于安装.卸载.升级和管理软件. 一个包由下面几个部分构成: 例如:ht ...

  8. python subplot 合并子图的方法

  9. linux安装以及相关配置

    计算机操作系统简介 操作系统是什么 操作系统的内核是什么 两种操作系统用户界面 安装Linux操作系统的准备工作 LINUX发行版(CENTOS.RHEL.FEDORA.UBUNTU.SUSE) RH ...

  10. Magento 本地搬家至网络服务器步骤

    1.将本地的Magento的数据库备份下来. 2.将本地的Magento网站资料做成ZIP资料. 3.将Magento网站 ZIP资料上传到服务器的域名指向的资料夹内. 4.将ZIP解压出来,移动到域 ...