Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr int N = 1e5+5;
- int n, ans = 0, s, f, z;
- vector<int> vec;
- void Solve()
- {
- cin >> n >> z;
- for (int i = 0, v; i < n; i++)
- cin >> v, vec.push_back(v);
- sort(vec.begin(), vec.end());
- s = (n-1)/2, f = n-1;
- for (; s >= 0 && f > (n-1)/2 ; ans+= (s >= 0 && f > (n-1)/2), f--, s--)
- while (s>=0&&(vec[f]-vec[s])<z)
- s--;
- cout << ans;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement