1 solutions

  • 0
    @ 2022-8-30 18:43:06
    #include<bits/stdc++.h>
    using namespace std;
    const int N=200010;
    int a[N];
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=n;i++)
    	cin>>a[i];
    	sort(a+1,a+n+1);
    	long long ans=0;
    	for(int i=1;i<=n;i++)
    	ans+=((upper_bound(a+1,a+n+1,a[i]+m)-a)-(lower_bound(a+1,a+n+1,a[i]+m)-a)); 
    	cout<<ans<<endl;
    	if(n>=10)
    	cout<<"QAQ"; 
    	return 0;
    }
    

    Information

    ID
    6548
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    45
    Accepted
    27
    Uploaded By