You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
710 B
C++
32 lines
710 B
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 2e5 + 50;
|
|
int a[N];
|
|
int main()
|
|
{
|
|
int n, z;
|
|
scanf("%d%d", &n, &z);
|
|
for (int i = 0; i < n; i++) scanf("%d", a + i);
|
|
//sort(a, a + n);
|
|
multiset<int> S(a, a + n);
|
|
int cnt = 0;
|
|
while (S.size() > 1)
|
|
{
|
|
auto ft = S.begin();
|
|
auto lb = S.lower_bound(*ft + z);
|
|
if (lb != S.end())
|
|
{
|
|
printf("** %d %d\n", *ft, *lb);
|
|
cnt++;
|
|
S.erase(lb);
|
|
S.erase(ft);
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
printf("%d", cnt);
|
|
return 0;
|
|
}
|