• 문제 링크
https://www.acmicpc.net/problem/11270
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.Queue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Queue<Integer> q = new ArrayDeque<>();
int n = read(), k = read(), max = 0;
while (n-- > 0) {
int i = read();
while (!q.isEmpty() && q.peek() <= i - 1000) q.poll();
max = Math.max(max, q.size());
q.offer(i);
}
bw.write(String.valueOf((max + k) / k));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 31884 Stacking Sticks - Data Structure / Java (0) | 2024.09.15 |
---|---|
[백준] 15237 Cipher - Data Structure / Java (0) | 2024.09.14 |
[백준] 16551 Potato Sacks - Backtracking / Java (0) | 2024.09.12 |
[백준] 8959 Stuttering Strings - Backtracking / Java (0) | 2024.09.11 |
[백준] 6977 Pattern Generator - Backtracking / Java (0) | 2024.09.10 |
댓글