-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj13335.java
More file actions
60 lines (48 loc) · 1.51 KB
/
boj13335.java
File metadata and controls
60 lines (48 loc) · 1.51 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class boj13335 {
static int n, w, L;
static Queue<Integer> truck;
static Queue<Integer> queue;
public static void main(String[] args) throws IOException {
input();
pro();
}
static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
w = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
truck = new LinkedList<>();
queue = new LinkedList<>();
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
truck.offer(Integer.parseInt(st.nextToken()));
}
for (int i = 0; i < w; i++) {
queue.offer(0);
}
}
static void pro() {
int time = 0;
int totalWeight = 0;
while (!queue.isEmpty()) {
time++;
totalWeight -= queue.poll();
if (!truck.isEmpty()) {
if (truck.peek() + totalWeight <= L) {
totalWeight += truck.peek();
queue.offer(truck.poll());
} else {
queue.offer(0);
}
}
}
System.out.println(time);
}
}