3tle
查看原帖
3tle
1328426
find_my_dawn楼主2024/3/30 23:25
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+5;
ll a[N];
ll n,c,ans; 
ll find(int x)
{   ll res=0;
	int h=0,t=n;
	int mid;
	while(h+1!=t)
	{	mid=(h+t)/2;
		if(a[mid]>=x) t=mid;
		else h=mid;
		}	
	while(a[t]==x) 
	{
	    t++;
	    res++;
	}
	return res;
}
int main()
{	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);   
	cin>>n>>c;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i--)
	{   int tmp=find(a[i]-c);		
	if(tmp)  ans+=tmp;
	}
	cout<<ans;
	return 0;
}
2024/3/30 23:25
加载中...