fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ll long long
  5. #define endl "\n"
  6. #define FOR(i, a, b) for (int i = a; i <= b; i++)
  7. #define FORD(i, a, b) for (int i = a; i > b; i--)
  8. #define FORu(i, a, b) for (int i = a; i < b; i++)
  9. #define vii vector <int>
  10. #define pb push_back
  11. #define fi first
  12. #define se second
  13. #define sz(a) (int)a.size()
  14. #define all(x) x.begin(), x.end()
  15. #define filei "BAI5.INP"
  16. #define fileo "BAI5.out"
  17. int main()
  18. {
  19. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  20. if (fopen(filei, "r"))
  21. {
  22. freopen(filei, "r", stdin);
  23. freopen(fileo, "w", stdout);
  24. }
  25. ll n; cin >> n;
  26. vector <ll> a(n);
  27. FORu(i, 0, n) cin >> a[i];
  28. sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end());
  29. ll ans = 0;
  30. for (ll &d: a)
  31. {
  32. ans = max(ans, (ll)(upper_bound(a.begin(), a.end(), d + n - 1) - lower_bound(a.begin(), a.end(), d)));
  33. }
  34. cout << n - ans;
  35.  
  36.  
  37.  
  38. }
Success #stdin #stdout 0.01s 5312KB
stdin
7
1 0 3 8 5 9 0
stdout
3