怎么改都神秘WA的代码:
#include <bits/stdc++.h>
using namespace std;
int n, ans;
long long dist, p[100005];
int main() {
cin >> n >> dist;
for (int i = 1; i <= n; i++) cin >> p[i];
sort(p + 1, p + n + 1);
for (int i = 1; i <= n - 2; i++) {
int j = i + 2;
while (j <= n && p[j] - p[i] <= dist) j++;
ans += (j - 1) - (i + 1);
}
cout << ans;
return 0;
}