|
| 1 | +import java.io.BufferedReader; |
| 2 | +import java.io.IOException; |
| 3 | +import java.io.InputStreamReader; |
| 4 | +import java.util.StringTokenizer; |
| 5 | + |
| 6 | +public class SB_15831 { |
| 7 | + static int N, B, W; |
| 8 | + static int[] walks; |
| 9 | + static int[] pebb = new int[2]; // 0:흰돌, 1:검정 |
| 10 | + static int mx = 0; |
| 11 | + public static void main(String[] args) throws IOException { |
| 12 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 13 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 14 | + |
| 15 | + N = Integer.parseInt(st.nextToken()); |
| 16 | + B = Integer.parseInt(st.nextToken()); // 검정 최대 개수 |
| 17 | + W = Integer.parseInt(st.nextToken()); // 흰색 최소 개수 |
| 18 | + |
| 19 | + walks = new int[N]; |
| 20 | + String line = br.readLine(); |
| 21 | + for (int i = 0; i < N; i++) { |
| 22 | + char c = line.charAt(i); |
| 23 | + walks[i] = (c == 'W') ? 0 : 1; |
| 24 | + } |
| 25 | + |
| 26 | + int left = 0; |
| 27 | + int right = 0; |
| 28 | + while (right < N) { |
| 29 | + pebb[walks[right]]++; // 오른쪽에 해당하는 색의 돌++ |
| 30 | + |
| 31 | + while (pebb[1]>B){ // 더이상 못갈경우 조건만족할때까지 left빼기 |
| 32 | + pebb[walks[left]]--; |
| 33 | + left++; |
| 34 | + } |
| 35 | + |
| 36 | + if (pebb[0] >= W){ // 흰돌 만족하면 거리 갱신 |
| 37 | + mx = Math.max(mx, right - left + 1); |
| 38 | + } |
| 39 | + right++; |
| 40 | + } |
| 41 | + System.out.println(mx); |
| 42 | + } |
| 43 | +} |
0 commit comments