0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-27 08:31:58 +00:00
OI-codes/Luogu/problem/P1296/P1296.cpp
2021-01-02 15:30:52 +08:00

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;
}