0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 22:08:47 +00:00
OI-codes/Luogu/P1296/P1296.cpp

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