Ankit_132

D

Jul 21st, 2023
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n, k;
  14.         cin>>n>>k;
  15.  
  16.         vector<int> a(n);
  17.         for(auto &e: a)     cin>>e;
  18.  
  19.         sort(a.begin(), a.end());
  20.  
  21.         int val = 1;
  22.  
  23.         for(int i=1, x=1; i<n; i++)
  24.         {
  25.             if(a[i]-a[i-1] <= k)
  26.                 x++;
  27.             else
  28.                 x=1;
  29.  
  30.             val = max(val, x);
  31.         }
  32.  
  33.         cout<<n - val<<"\n";
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment