fork download
  1. // F - Balanced Team
  2. #define DaAbyad ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. const int N = 1e5 + 5, MOD = 1e9 + 7;
  6. const long long oo = 1e18 + 5;
  7. const long double pi = acos(-1);
  8. const long double eps = 1e-9;
  9. template<class T>
  10. using rpq = priority_queue<T, vector<T>, greater<T>>;
  11.  
  12. void open_file(string filename) {
  13. freopen((filename + ".in").c_str(), "r", stdin);
  14. freopen((filename + ".out").c_str(), "w", stdout);
  15. }
  16.  
  17. void Magic() {
  18. int n;
  19. cin >> n;
  20. vector<int> v(n);
  21. for (int i = 0; i < n; ++i) {
  22. cin >> v[i];
  23. }
  24. sort(v.begin(), v.end());
  25. int ans = 0;
  26. int j = 0;
  27. for (int i = 0; i < n; ++i) {
  28. while (j < n && v[i] + 5 >= v[j]) {
  29. j++;
  30. ans = max(ans, j - i);
  31. }
  32. }
  33. cout << ans;
  34. }
  35.  
  36. signed main() {
  37. DaAbyad
  38. int tests = 1;
  39. // cin >> tests;
  40. while (tests--) {
  41. Magic();
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
32765