fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define ld long double
  7. #define vll vector<ll>
  8. #define pb push_back
  9. #define f first
  10. #define se second
  11. #define endl '\n'
  12. #define Left Node << 1
  13. #define Right Node << 1 | 1
  14. #define INF -1e9
  15. #define Fast() {ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
  16.  
  17. void solve()
  18. {
  19. int n;
  20. cin >> n;
  21.  
  22. vector<int> a(n);
  23. for (int &it : a)
  24. cin >> it;
  25.  
  26. sort(a.begin(), a.end());
  27.  
  28. int ans = 1;
  29. for (int i = 0; i < n; i++) {
  30. int pos = upper_bound(a.begin(), a.end(), a[i] + 5) - a.begin();
  31.  
  32. ans = max(ans, pos - i);
  33. }
  34.  
  35. cout << ans << endl;
  36. }
  37.  
  38. int main()
  39. {
  40. Fast();
  41.  
  42. int t = 1;
  43. // cin >> t;
  44. while (t--)
  45. {
  46. solve();
  47. }
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
32764