mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-30 19:36:27 +00:00
18 lines
342 B
C++
18 lines
342 B
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int main() {
|
|
int n, d, p[100005], ans = 0;
|
|
cin >> n >> d;
|
|
for (int i = 0; i < n; i++) {
|
|
cin >> p[i];
|
|
}
|
|
sort(p, p + n);
|
|
for (int i = 0; i < n; i++) {
|
|
ans += (upper_bound(p + i, p + n, p[i] + d) - p) - i - 1;
|
|
}
|
|
cout << ans << endl;
|
|
return 0;
|
|
}
|