-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path트럭.java
More file actions
44 lines (36 loc) · 1.44 KB
/
트럭.java
File metadata and controls
44 lines (36 loc) · 1.44 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int w = Integer.parseInt(st.nextToken());
int L = Integer.parseInt(st.nextToken());
int[] truck = new int[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
truck[i] = Integer.parseInt(st.nextToken());
}
Queue<Integer> bridge = new ArrayDeque<>();
int time = 0, sum = 0, idx = 0;
while (idx < n || sum > 0) {
time++; // 시간 증가
if (bridge.size() == w) // 맨 앞칸 뺀다
sum -= bridge.poll();
if (idx < n && sum + truck[idx] <= L) { // 무게 L보다 작고 w보다 적게 있음
bridge.offer(truck[idx]);
sum += truck[idx];
idx++;
} else { // 다리에 새로운 차 못들어가는 경우 (이동만 시켜야 함)
bridge.offer(0);
}
}
System.out.println(time);
}
}