fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int k;
  6. cin>>k;
  7. string s;
  8. cin>>s;
  9. set<char> g;int diff=0;
  10. int p=0;
  11. for(int i=0,j=0;j<s.size();j++)
  12. {
  13. g.insert(s[j]);
  14. diff= *g.rbegin()-*g.begin();
  15. while(diff>k)
  16. {
  17. g.erase(s[i]);
  18. i++;
  19. diff=*g.rbegin()-*g.begin();
  20. }
  21. int l=j-i+1;
  22. p=max(p,l);
  23.  
  24.  
  25.  
  26. }
  27. cout<<p;
  28.  
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty