Skip to content

Commit 282b60d

Browse files
committed
이예진: [BOJ] 15831 준표의 조약돌_241122
1 parent ce02170 commit 282b60d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

BOJ/15001-20000번/YJ_15831.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class YJ_15831 {
5+
public static void main(String[] args) throws IOException {
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
StringTokenizer st = new StringTokenizer(br.readLine());
8+
int N = Integer.parseInt(st.nextToken());
9+
int B = Integer.parseInt(st.nextToken());
10+
int W = Integer.parseInt(st.nextToken());
11+
String[] road = br.readLine().split("");
12+
13+
int result = 0;
14+
int bCount = 0;
15+
int wCount = 0;
16+
int start = 0;
17+
int end = 0;
18+
while(end < N){
19+
if(bCount > B){ //b 갯수를 초과한 경우 start 움직이기
20+
if("W".equals(road[start])){
21+
--wCount;
22+
}else{
23+
--bCount;
24+
}
25+
start++;
26+
} else { //b 갯수보다 작거나 같은 경우 end 움직이기
27+
if("W".equals(road[end])){
28+
wCount++;
29+
}else{
30+
bCount++;
31+
}
32+
end++;
33+
}
34+
35+
if(wCount >= W && bCount <= B) { //조건이 부합하는 경우 산책길 길이 갱신
36+
result = Math.max(result, end - start);
37+
}
38+
}
39+
40+
System.out.println(result);
41+
}
42+
}

0 commit comments

Comments
 (0)