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, cnt = 0; cin >> n;
  26. vector <ll> a;
  27. FORu(i, 0, n)
  28. {
  29. ll x; cin >> x;
  30. if (x == 0) cnt++;
  31. else a.pb(x);
  32. }
  33. sort(a.begin(), a.end());
  34. ll max_len = 0;
  35. FORu(i, 0, sz(a))
  36. {
  37. ll j = i;
  38. while (j + 1 < sz(a) && a[j + 1] == a[j] + 1)
  39. {
  40. j++;
  41. }
  42. max_len = max(max_len, j - i + 1);
  43. i = j;
  44. }
  45. cout << max_len;
  46.  
  47.  
  48.  
  49.  
  50. }
Success #stdin #stdout 0.01s 5288KB
stdin
7
1 0 3 8 5 9 0
stdout
2