#P1296. 奶牛的耳语
奶牛的耳语
Description
In your cattle farm, all cows are kept in a row of stalls arranged along a straight line. There are cows, and the position of the -th cow on the line is represented by an integer coordinate . On boring days, cows often share gossip from their own stalls. Each cow speaks with the same loudness, but due to sound attenuation, a cow’s voice can only be heard by cows within a distance no greater than . In this case, the pair of cows is said to be able to communicate with each other. Given all cows’ positions and the maximum propagation distance , please write a program to compute how many pairs of cows in your farm can communicate.
Input Format
The first line contains two integers .
The second line contains integers, each being a coordinate , describing a cow’s position on the line.
Output Format
A single integer, the number of pairs of cows in the farm that can communicate.
5 10
10 12 16 37 40
4
Hint
Constraints
- For of the data, .
- For of the data, .
Translated by ChatGPT 5
京公网安备 11011102002149号