File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments