Advertisement
Saleh127

CF 676C

Oct 25th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll a,c,d,e,i,j,k,l;
  11. string x;
  12. cin>>a>>c>>x;
  13.  
  14. d=e=k=l=0;
  15. for(i=0;i<a;i++)
  16. {
  17. if(x[i]=='a') d++;
  18. else e++;
  19. if(min(d,e)>c)
  20. {
  21. if(x[k]=='a') d--;
  22. else e--;
  23. k++;
  24. }
  25. else l=max(l,d+e);
  26. }
  27. cout<<l<<endl;
  28.  
  29. return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement