金丝猴人
查看原帖
金丝猴人
1614450
lrj100815楼主2025/1/6 15:10

十年OI一场空(如果你WA#3) 不信试试(尽管我也不知道为啥)

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
signed main() {
	int n,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=((upper_bound(a+1,a+n+1,a[i]+c)-a)-(lower_bound(a+1,a+n+1,a[i]+c)-a));
	}
	cout<<ans;
	return 0;
}
2025/1/6 15:10
加载中...