fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9. vector<int> v(n);
  10. for (int i = 0; i < n; i++)
  11. cin >> v[i];
  12. sort(v.begin(), v.end());
  13. int len = 0, count = 1, first = v[0];
  14. for (int i = 1; i < v.size(); i++) {
  15. if (first == v[i] || first + 1 == v[i])
  16. count++;
  17. else {
  18. if (count > len)
  19. len = count;
  20. count = 1;
  21. first = v[i];
  22. }
  23. }
  24. cout << max(len, count) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 5576KB
stdin
6
1 2 2 3 1 2
stdout
5