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. 剑指Offer——序列化二叉树

    题目描述: 请实现两个函数,分别用来序列化和反序列化二叉树 分析: 先序遍历可以用来序列化二叉树,序列化过程中,我们用“0xFFFFFFFF”表示结点为NULL. 反序列化便很简单,遇到“0xFFFF ...

  2. Linux命令:nl

    全称:number lines of files 用途:显示的时候添加行号. 格式:nl [OPTION]... [FILE]... 类型:nl is /usr/bin/nl 说明: 该命令主要就是针 ...

  3. 十個必用的 Vim Plugin

    ◎ The NERD Tree 操作 Vim 時,通常都在 Terminal 底下作用,無法像一般的 GUI    應用程式可以以樹狀目錄來瀏覽檔案. The NERD Tree    是一將檔案目錄 ...

  4. Mybatis框架学习总结-Mybatis框架搭建和使用

    Mybatis介绍 Mybatis是一个支持普通SQL查询,存储过程,和高级映射的优秀持久层框架.Mybatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.Mybatis可以使 ...

  5. Elasticsearch.js 发布 —— 在Node.js和浏览器中调用Elasticsearch

    继PHP.Ruby.Python和Perl之后,Elasticsearch最近发布了Elasticsearch.js,Elasticsearch的JavaScript客户端库.可以在Node.js和浏 ...

  6. 015-HQL中级5-hive创建索引

    索引是hive0.7之后才有的功能,创建索引需要评估其合理性,因为创建索引也是要磁盘空间,维护起来也是需要代价的 创建索引 hive> create index [index_studentid ...

  7. Portal系统中当切换学生时仍旧停留在当前页面的实现方法

    一.BaseController.cs文件 1.OnActionExecuting方法,该方法可以被各子Controller重写 protected override void OnActionExe ...

  8. Linux系统——本地yum仓库安装

    一.yum仓库概述 yum是基于rpm包管理,能够从指定的服务器自动下载rpm包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无需繁琐地一次次下载.安装. 二.yum仓库安装的方式 ...

  9. hdu1403 Longest Common Substring

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1403 题目: Longest Common Substring Time Limit: 800 ...

  10. 【npm】使用淘宝提供的镜像来加速npm

    国外的npm用着非常不稳定,时常一直就卡在安装的进度条上 淘宝提供了一个国内镜像,保障了安装网络环境的稳定,和源地址10分钟同步一次,没有被收录的包会自动切换到npm官方下载,并添加进镜像库. 地址: ...