[Link] 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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] split = br.readLine().split(" ");
StringBuilder sb = new StringBuilder();
int n = atoi(split[0]), l = atoi(split[1]), minIdx = 0;
Deque<Nidx> q = new ArrayDeque<>();
split = br.readLine().split(" ");
for(int i = 0; i < n; i++) {
if(!q.isEmpty() && q.peek().idx <= i - l) q.poll();
while(!q.isEmpty() && q.peekLast().val >= atoi(split[i])) q.pollLast();
q.add(new Nidx(atoi(split[i]), i));
sb.append(q.peek().val + " ");
}
System.out.println(sb);
}
static class Nidx{
int val;
int idx;
public Nidx(int val, int idx) { this.val = val; this.idx = idx; }
}
static int atoi(String s) { return Integer.parseInt(s); }
}