37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
|
#include<stdio.h>
|
||
|
#include<vector>
|
||
|
#include <algorithm>
|
||
|
using namespace std;
|
||
|
|
||
|
int main(){
|
||
|
long long int m,k,h;
|
||
|
long long int sum=0;
|
||
|
scanf("%lld %lld %lld",&m,&k,&h);
|
||
|
int *steps=new int[m];
|
||
|
for(int i=0;i<m;i++){
|
||
|
scanf("%d",&steps[i]);
|
||
|
}
|
||
|
vector<int> insightSteps;
|
||
|
for(long long int i=0;i<k&&i<m;i++){
|
||
|
insightSteps.push_back(steps[i]);
|
||
|
}
|
||
|
sort(insightSteps.begin(),insightSteps.end());
|
||
|
for(long long int i=0;i<m;i++){
|
||
|
insightSteps.erase(find(insightSteps.begin(),insightSteps.end(),steps[i]));
|
||
|
auto ip=insightSteps.begin();
|
||
|
if(i+k<m){
|
||
|
ip=lower_bound(insightSteps.begin(),insightSteps.end(),steps[i+k]);
|
||
|
insightSteps.insert(ip,steps[i+k]);
|
||
|
}
|
||
|
long long int lowest=steps[i]-h;
|
||
|
lowest=lowest<0?0:lowest;
|
||
|
long long int highest=steps[i]+h;
|
||
|
highest=highest>2147483647?2147483647:highest;
|
||
|
auto lb=lower_bound(insightSteps.begin(),insightSteps.end(),lowest);
|
||
|
auto ub=upper_bound(insightSteps.begin(),insightSteps.end(),highest);
|
||
|
sum+=ub-lb;
|
||
|
}
|
||
|
printf("%lld\n",sum);
|
||
|
delete[] steps;
|
||
|
return 0;
|
||
|
}
|