Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Codeforces
- {
- public static void main(String args[])throws Exception
- {
- BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
- StringBuilder sb=new StringBuilder();
- String s[]=bu.readLine().split(" ");
- int n=Integer.parseInt(s[0]),i,l=0,c[]=new int[26],ans=0;
- long x=Long.parseLong(s[1]),cur=0;
- char a[]=bu.readLine().toCharArray();
- for(i=0;i<n;i++)
- {
- int y=a[i]-'a';
- c[y]++;
- if(y==1) cur+=c[0];
- while(cur>x)
- {
- y=a[l++]-'a';
- c[y]--;
- if(y==0) cur-=c[1];
- }
- ans=Math.max(ans,i-l+1);
- }
- System.out.println(ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement