amine99

Untitled

Feb 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define loop(i,b,e) for(int i=b;i<=e;i++)
  5. #define pf printf
  6. #define sf scanf
  7.  
  8. int n,d,b,e,t[101],ans=1e7;
  9.  
  10. int main() {
  11.    sf("%d%d",&n,&d);
  12.    loop(i,0,n-1)
  13.       sf("%d",&t[i]);
  14.    if(n == 1) {
  15.       pf("0");
  16.       return 0;
  17.    }
  18.    sort(t,t+n);
  19.    loop(i,0,n-1) {
  20.       loop(j,0,n-1) {
  21.          if(t[i]-t[j] == d) {
  22.             ans = min(ans,n-i+j-1);
  23.          }
  24.       }
  25.    }
  26.    pf("%d",ans);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment