cswork / OA打开练习工作台

AmazonOA #18

Get Computational Equivalents

估计中等可在线判题

考点(AI 标注)双指针滑窗二分查找

Given an array of process loads and a threshold m, count unordered pairs (i,j) of distinct indices whose loads differ by at most m in absolute value. Each pair is counted once; pairs with equal values but different indices are counted too.

输入格式

The first line contains n m (1≤n≤200000, 0≤m≤10⁸), and the second line contains n loads (1..10⁸). The answer may exceed the range of a 32-bit integer.

输出格式

Output a single integer, the answer required by the problem.

样例 1

输入:

4 3
7 10 13 11

输出:

4

样例 2

输入:

3 0
5 5 5

输出:

3

样例 3

输入:

1 0
1

输出:

0

样例说明

The valid load pairs in example 1 are (7,10), (10,13), (10,11), (13,11), 4 pairs in total.