P25402 [AtCoder] Make a Team
提高-
题目描述

Problem Description

There are $ N $ members in the competitive programming club at Rask's university. The rating of the $ i $-th member is $ R_i $.

For a university-wide programming contest, it has been decided to form one team by selecting $ 3 $ members from the club.

Here, the difference between the highest and lowest ratings within the team should be $ D $ or less.

Calculate the number of ways to form such a team.

Input Format

The input is given from the standard input in the following format:

$ N $ $ D $ $ R_1 $ $ R_2 $ $\ldots$ $ R_N $

Output Format

Output the number of ways to form a team that satisfies the condition.

Note that the answer may not fit into a 32-bit integer type.

Sample Input and Output

Sample Input #1

5 400
300 700 1000 800 500

Sample Output #1

3

Sample Input #2

3 1000
2000 2000 4000

Sample Output #2

0

Sample Input #3

6 314159265
358979323 846264338 327950288 419716939 93751058 209749445

Sample Output #3

7

Notes/Hints

Constraints

  • All inputs are integers.
  • $3 \leq N \leq 10^5$
  • $1 \leq D \leq 10^9$
  • $1 \leq R_i \leq 10^9$

Sample Explanation 1

There are $ 3 $ ways: (member $ 1 $, member $ 2 $, member $ 5 $), (member $ 2 $, member $ 3 $, member $ 4 $), (member $ 2 $, member $ 4 $, member $ 5 $).

Sample Explanation 2

There may be no way to form a team that satisfies the condition.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 400 300 700 1000 800 500
样例输出
3