jakaria_hossain

codeforce - vasya and strings

May 16th, 2019
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m;
  4. string s;
  5. typedef long long ll;
  6. ll func(char x)
  7. {
  8. ll ans=0,i=0,j=0,cnt=0;
  9. for(i=0; i<n; i++)
  10. {
  11. if(s[i]==x)cnt++;
  12. if(cnt>m)
  13. {
  14. while(cnt>m)
  15. {
  16. if(s[j++]==x)
  17. cnt--;
  18. }
  19. }
  20. ans=max(ans,i-j+1);
  21.  
  22. }
  23. return ans;
  24. }
  25. int main()
  26. {
  27. cin>>n>>m;
  28. cin>>s;
  29. ll a,b;
  30. a=func('a');
  31. b=func('b');
  32. a=max(a,b);
  33. cout<<a<<endl;
  34. return 0;
  35. }
RAW Paste Data