先输入数据到A数组,将前后数据作差放入B数组,然后对B数组内的数据sort排序
这样再进行二分,拿右边界减去左边界
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int n=1e6+10;
int A[n];int B[n];
signed main()
{
IOS
int N,C;
cin>>N>>C;
for(int i=0;i<N;++i) cin>>A[i];
for(int i=1;i<N;++i)
{
B[i]=A[i]-A[i-1];
}
sort(B+1,B+N);
int l,r;
l=lower_bound(B+1,B+N,C)-B;
r=upper_bound(B+1,B+N,C)-B;
int ans=r-l+1;
cout<<ans;
return 0;
}
蒟蒻的求助,求大佬帮助