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:
parent
0d963e43c2
commit
46a0e2b369
17
problem/P1296/P1296.cpp
Normal file
17
problem/P1296/P1296.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user