0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 19:32:12 +00:00
OI-codes/Luogu/P1296/P1296.cpp

18 lines
342 B
C++
Raw Normal View History

2020-10-16 13:40:54 +00:00
#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;
}