0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P1296 奶牛的耳语

R39921316
This commit is contained in:
Baoshuo Ren 2020-10-16 21:40:54 +08:00 committed by Baoshuo Ren
parent 0d963e43c2
commit 46a0e2b369
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

17
problem/P1296/P1296.cpp Normal file
View File

@ -0,0 +1,17 @@
#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;
}