Advertisement
Guest User

2 pointer

a guest
Mar 25th, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Codeforces
  5. {
  6.     public static void main(String args[])throws Exception
  7.     {
  8.         BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
  9.         StringBuilder sb=new StringBuilder();
  10.         String s[]=bu.readLine().split(" ");
  11.         int n=Integer.parseInt(s[0]),i,l=0,c[]=new int[26],ans=0;
  12.         long x=Long.parseLong(s[1]),cur=0;
  13.         char a[]=bu.readLine().toCharArray();
  14.         for(i=0;i<n;i++)
  15.         {
  16.             int y=a[i]-'a';
  17.             c[y]++;
  18.             if(y==1) cur+=c[0];
  19.             while(cur>x)
  20.             {
  21.                 y=a[l++]-'a';
  22.                 c[y]--;
  23.                 if(y==0) cur-=c[1];
  24.             }
  25.             ans=Math.max(ans,i-l+1);
  26.         }
  27.         System.out.println(ans);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement