Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
a1.cpp 528 Bytes
Copy Edit Raw Blame History
刘嘉霖 authored 2024-04-08 22:24 . 蓝桥备赛代码
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
const int N=200000;
long arr[N];
long n,c;
long ans;
int main ()
{
cin>>n>>c;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
for(int i=0;i<n;i++)
{
//ʹarriA
int j=arr[i]+c;
int a1=lower_bound(arr+i,arr+n,j)-arr;
int a2=upper_bound(arr+i,arr+n,j)-arr;
ans+=upper_bound(arr+i,arr+n,j)-lower_bound(arr+i,arr+n,j);
}
cout<<ans<<endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化