Advertisement
domybest100

개미 집합

Aug 22nd, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int arr[100001];
  5. int main() {
  6.     int n, d, ans = 1000001;
  7.     cin >> n >> d;
  8.     for (int i = 0; i < n; i++) cin >> arr[i];
  9.     sort(arr, arr + n);
  10.     int i = 0, j = 0;
  11.     while (j < n){
  12.         if (arr[j] - arr[i] > d) i++;
  13.         else{
  14.             ans = min(ans, n+i-j);
  15.             j++;
  16.         }
  17.     }
  18.     cout << ans-1 << endl;
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement