https://www.acmicpc.net/problem/15831
import java.util.*;
import java.io.*;
public class Main
{
public static int solution(String word, int n , int w , int b){
int right=0;
int b_count=0;
int w_count=0;
int ans=0;
for(int left=0; left<n;left++){
while(b_count<=b && right<n){
if(word.charAt(right)=='W'){
w_count++;
}else{
b_count++;
}
if(w_count>=w && b_count<=b){
ans=Math.max(ans,w_count+b_count);
}
right++;
}
if(word.charAt(left)=='W'){
w_count--;
}else{
b_count--;
}
}
return ans;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] input1 = br.readLine().split(" ");
int n = Integer.parseInt(input1[0]);
int b = Integer.parseInt(input1[1]);
int w = Integer.parseInt(input1[2]);
String word = br.readLine();
bw.write(solution(word,n, w,b)+"");
bw.flush();
}
}
import java.util.Scanner;
class Main
{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int B = sc.nextInt();
int W = sc.nextInt();
char[] color = sc.next().toCharArray();
int currentWhiteCount = 0;
int currentBlackCount = 0;
int ansLength = 0;
int nextIndex = 0;
for (int i = 0; i < N; i++) {
while (nextIndex < N) {
if (currentBlackCount == B && color[nextIndex] == 'B') break;
if (color[nextIndex++] == 'W') currentWhiteCount++;
else currentBlackCount++;
}
if (currentWhiteCount >= W)
ansLength = Math.max(ansLength, nextIndex - i);
if (color[i] == 'W') currentWhiteCount--;
else currentBlackCount--;
}
System.out.println(ansLength);
}
}
'Problem Solving > 투포인터' 카테고리의 다른 글
BOJ14465 소가 길을 건너간 이유 5 (0) | 2024.03.05 |
---|---|
BOJ16472 고냥이 (0) | 2024.03.04 |
BOJ17609 회문 (0) | 2024.03.04 |
BOJ11728 배열합치기 (0) | 2024.03.04 |
BOJ2118 두개의 탑*R (0) | 2024.03.03 |