CF32A.Reconnaissance

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are _a_1, _a_2, ..., a__n centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.

Ways (1, 2) and (2, 1) should be regarded as different.

根据贝尔兰军队的规定,一支侦察小队必须恰好由两名士兵组成。由于这两名士兵的身高不应相差太大,因此他们的身高差最多为 dd 厘米。鲍勃上尉的分队中有 nn 名士兵,他们的身高分别为 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n 厘米。部分士兵身高相同。鲍勃想知道,从他的分队中选出两名士兵组成一支侦察小队,共有多少种方式。

方式 (1, 2)(1,\,2) 和 (2, 1)(2,\,1) 应被视为不同的方式。

输入格式

The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.

第一行包含两个整数 nn 和 dd(1≤n≤10001 \leq n \leq 1000,1≤d≤1091 \leq d \leq 10^9)—— 分别表示鲍勃部队中的士兵人数和允许的最大身高差。
第二行包含 nn 个用空格分隔的整数——表示鲍勃部队中所有士兵的身高。这些数值均不超过 10910^9。

输出格式

Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.

输出一个数字——组成一支侦察小队(由两名士兵组成)的方案数,要求这两名士兵的身高差不超过 dd。

输入输出样例

  • 输入#1

    5 10
    10 20 50 60 65

    输出#1

    6
  • 输入#2

    5 1
    55 30 29 31 55

    输出#2

    6

输入解题思路,AI测评打分。不知道怎么写?

首页