Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. n,k =map(int, input().split())
  2. s=input()
  3. a=b=i=0
  4. cur=k
  5. ans=0
  6. while b != n:
  7. if s[b]=='b':
  8. if cur:
  9. if cur != 1:
  10. b += 1
  11. cur-=1
  12. else:
  13. while(s[a] == 'a'):
  14. a+=1
  15. ++cur
  16. if(a==n):
  17. b=n
  18. break
  19. a+=1
  20. else:
  21. b+=1
  22. ans = max(ans, b - a + 1)
  23. #print(a,b)
  24.  
  25. a=b=i=0
  26. cur=k
  27. while b != n:
  28. if s[b]=='a':
  29. if cur:
  30. b += 1
  31. cur-=1
  32. else:
  33. while(s[a] == 'b'):
  34. a+=1
  35. ++cur
  36. if (a == n):
  37. b = n
  38. break
  39. a+=1
  40. else:
  41. b+=1
  42. ans = max(ans, b - a + 1)
  43. print(a,b)
  44.  
  45. print(min(ans, len(s)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement