fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAXH = 500000;
  5.  
  6. vector<int> P[1 + MAXH];
  7.  
  8. int main()
  9. {
  10. int k, n;
  11. cin >> n >> k;
  12. for (int i = 0; i < n; ++i) {
  13. int h;
  14. cin >> h;
  15. P[h].push_back(i);
  16. }
  17. int b = 0;
  18. for (int h = 1; h <= MAXH; ++h) {
  19. for (int i = 0, j = 0; j < (int)P[h].size(); ++j) {
  20. int a = P[h][j] - P[h][i] + 1;
  21. int c = j - i + 1;
  22. while (a - c > k) {
  23. ++i;
  24. a = P[h][j] - P[h][i] + 1;
  25. c = j - i + 1;
  26. }
  27. b = max(b, c);
  28. }
  29. }
  30. cout << b << endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 26952KB
stdin
10 2
185 180 185 185 180 190 185 185 190 195
stdout
4