Skip to content

Commit

Permalink
CT_344
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-Good committed Dec 24, 2024
1 parent 3b776fc commit 4e823ba
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions BOJ/Java/src/S2/Boj_30804_과일탕후루.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package S2;

import java.io.*;
import java.util.StringTokenizer;

public class Boj_30804_과일탕후루 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];

StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}

int[] cntList = new int[10];
int max = 0;
int nowCnt = 0;
int start = 0;

for (int end = 0; end < N; end++) {
if (++cntList[arr[end]] == 1) {
if (++nowCnt > 2) {
max = Math.max(max, end - start);
while (start <= end) {
if (--cntList[arr[start++]] == 0) nowCnt--;
if (nowCnt <= 2) break;
}
}
}
}

max = Math.max(max, N - start);

bw.write(Integer.toString(max));
bw.flush();
}
}

0 comments on commit 4e823ba

Please sign in to comment.