-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.java
58 lines (48 loc) · 1.7 KB
/
Main.java
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
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 Main {
private static int n;
private static int distance;
private static int limit;
private static Queue<Integer> trucks;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
distance = Integer.parseInt(st.nextToken());
limit = Integer.parseInt(st.nextToken());
trucks = new LinkedList<>();
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
trucks.add(Integer.parseInt(st.nextToken()));
}
System.out.println(sol());
}
public static int sol() {
Queue<Integer> bridge = new LinkedList<>();
for (int i = 0; i < distance-1; i++){
bridge.offer(0);
}
bridge.offer(trucks.peek());
int total = trucks.poll();
int res = 1;
while (!bridge.isEmpty()){
int front = bridge.poll();
res++;
total -= front; // 트럭이 빠져 나가면 총 무게 빼주기
if (!trucks.isEmpty()){
if(total + trucks.peek() <= limit){ // 다음 트럭이 올라와도 되는 상황
int newtruck = trucks.poll();
bridge.offer(newtruck);
total += newtruck;
} else bridge.offer(0);
}
}
return res;
}
}