12 条题解

  • 1
    @ 2025-5-10 19:40:25
    #include <bits/stdc++.h>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    int n , c , a[N];
    int sum;
    int main()
    {
    	cin >> n >> c;
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		cin >> a[i];
    	}
    	sort( a + 1 , a + n + 1 );
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		sum += upper_bound( a + 1 , a + n + 1 , a[i] + c ) - lower_bound( a + 1 , a + n + 1 , a[i] + c );
    	}
    	cout << sum;
    	return 0;
    }
    
    //菜鸟驿站
    //老六专属

    信息

    ID
    1279
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    493
    已通过
    123
    上传者