728x90
반응형
https://www.acmicpc.net/problem/11003
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;
public class Main {
static class Node {
int value;
int idx;
Node(int value, int idx) {
this.value = value;
this.idx = idx;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(st.nextToken());
int L = Integer.parseInt(st.nextToken());
Deque<Node> deque = new ArrayDeque<>();
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int value = Integer.parseInt(st.nextToken());
while (!deque.isEmpty() && deque.peekLast().value > value) {
deque.pollLast();
}
deque.offer(new Node(value, i));
if (deque.peek().idx < i - (L - 1)) {
deque.poll();
}
sb.append(deque.peek().value).append(" ");
}
System.out.println(sb.toString());
}
}
|
cs |
728x90
'Algorithm > BOJ' 카테고리의 다른 글
백준) 11052_카드 구매하기 (0) | 2023.05.16 |
---|---|
백준) 1074_Z (0) | 2023.05.16 |
백준) 21276_계보 복원가 호석 (2) | 2023.05.13 |
백준) 1766_문제집 (1) | 2023.05.13 |
백준) 1005_ACM Craft (1) | 2023.05.13 |