Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, m;
- cin>>n>>m;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- sort(a.begin(), a.end());
- int ans = 0;
- int i = 0;
- for(auto e: a)
- {
- int x = lower_bound(a.begin(), a.end(), e+m) - a.begin() - (i++);
- ans = max(ans, x);
- }
- cout<<ans<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment