22行
2025-07-24 19:55:35
发布于:江苏
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int a[200005];
bool cmp(int x,int y)
{
return x < y;
}
int main()
{
int n,c;
cin >> n >> c;
for(int i = 1; i<= n; i++)cin >> a[i];
int cnt = 0;
sort(a+1,a+n+1,cmp);
for(int i = 1; i<= n; i++)
{
int A = a[i] + c;
cnt += upper_bound(a+1,a+n+1,A) - lower_bound(a+1,a+n+1,A);
}
cout << cnt;
return 0;
}
这里空空如也
有帮助,赞一个