Problem Link
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 100000;
int main()
{
LL n , d;
LL arr[N + 1];
int p = 0;
cin >> n >> d;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
}
sort(arr, arr + n);
for(int i = 0; i < n - 1;)
{
if(arr[i + 1] - arr[i] <= d)
{
p++;
i += 2;
}
else
i++;
}
cout << p << endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 100000;
int main()
{
LL n , d;
LL arr[N + 1];
int p = 0;
cin >> n >> d;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
}
sort(arr, arr + n);
for(int i = 0; i < n - 1;)
{
if(arr[i + 1] - arr[i] <= d)
{
p++;
i += 2;
}
else
i++;
}
cout << p << endl;
return 0;
}
Comments
Post a Comment