백준
백준 13335 트럭(Java)
Park DJ
2023. 2. 24. 00:05
https://www.acmicpc.net/problem/13335
13335번: 트럭
입력 데이터는 표준입력을 사용한다. 입력은 두 줄로 이루어진다. 입력의 첫 번째 줄에는 세 개의 정수 n (1 ≤ n ≤ 1,000) , w (1 ≤ w ≤ 100) and L (10 ≤ L ≤ 1,000)이 주어지는데, n은 다리를 건너는 트
www.acmicpc.net
Java 코드
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Queue<Integer> t = new LinkedList<>();
Queue<Integer> q = new LinkedList<>();
int time = 0;
int weight = 0;
int n = sc.nextInt();
int w = sc.nextInt();
int l = sc.nextInt();
for(int i = 0; i < n; i++) t.add(sc.nextInt());
for(int i = 0; i < w; i++) q.add(0);
while(!q.isEmpty()) {
weight -= q.poll();
time++;
if(!t.isEmpty()) {
if(t.peek() + weight <= l) {
weight += t.peek();
q.add(t.poll());
}
else q.add(0);
}
}
System.out.println(time);
}
}