不是,洛谷你干嘛嗨嗨you
,这题为啥不给我过?求大佬帮助,我这题是用upper_bound和lower_bound写的
不知为什么出现了玄学错误
废话不对说,给代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,c,a[200005];
int ans=0;
int main(){
cin >> n >> c;
for(int i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
ans += upper_bound(a+1,a+1+n,a[i]+c) - lower_bound(a+1,a+1+n,a[i]+c);
}
cout << ans;
return 0;
}
┏┛墓┗┓