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. llvm,gcc

    GCC,LLVM,Clang编译器对比   在XCode中,我们经常会看到这些编译选项(如下图),有些人可能会有些茫然,本文将对GCC4.2.LLVM GCC 4.2.LLVM compliler 2 ...

  2. 设计模式之Prototype模式

    通常我们会使用new 类名()的方法会去生成一个新的实例,但在开发过程中,有时候也会有"在不指定类名的前提下生成实例"的需求,那样,就只能根据现有实例来生成新的实例. 有三种情况, ...

  3. How many---hdu2609(最小表示)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 给你n个01串,然后求这n个串中有几个不同的: 例如:1100 ,1001 ,0011 ,011 ...

  4. Linux环境下NodeJS的安装配置(HelloWorld)

    Linux环境下NodeJS的安装配置(HelloWorld) 最简单的环境安装,测试helloworld.给初学者!! 安装脚本,请仔细阅读逐行执行: #!/bin/bash #检查是否已经安装 r ...

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

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

  6. C语言可以分配的最大内存

    前言 最近用C刷PAT算法题目, 发现C语言有太多需要关注大小范围的东西必须 知道, 虽说挺麻烦, 但也挺有意思. int最大值是多少 首先就是int类型的取值范围, 这个太常用. C语言标准规定最低 ...

  7. [React-Native]入门(Hello World)

    (1)需要一台Mac(OSX),这个是前提,建议还是入手一本啦. (2)在Mac上安装Xcode,建议Xcode 6.3以上版本 (3)安装node.js:https://nodejs.org/dow ...

  8. maven安装配置参数化打包命令

    Maven使用 maven的配置文件看似很复杂,其实只需要根据项目的实际背景,设置个别的几个配置项而已.maven有自己的一套默认配置,使用者除非必要,并不需要去修改那些约定内容.这就是所谓的“约定优 ...

  9. 从u-boot的编译结果中提取include目录

    ac@DESKTOP-BJ1MJGM:~/u-boot-2019.01/spl$ arm-linux-gnueabihf-objdump -g u-boot-spl | awk '/The Direc ...

  10. C#如何获取枚举(Enum)变量的值

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Enum ...