Ankit_132

C

Oct 28th, 2023
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, m;
  7.     cin>>n>>m;
  8.     vector<int> a(n);
  9.     for(auto &e: a) cin>>e;
  10.  
  11.     sort(a.begin(), a.end());
  12.  
  13.     int ans = 0;
  14.     int i = 0;
  15.     for(auto e: a)
  16.     {
  17.         int x = lower_bound(a.begin(), a.end(), e+m) - a.begin() - (i++);
  18.         ans = max(ans, x);
  19.     }
  20.     cout<<ans<<"\n";
  21. }
Advertisement
Add Comment
Please, Sign In to add comment