슈콩

[BOJ] 백준 13335 트럭 본문

Algorithms/Baekjoon

[BOJ] 백준 13335 트럭

shukong 2025. 9. 17. 20:32

[문제]

https://www.acmicpc.net/problem/13335

 

 

[소스 코드]

import java.io.*;
import java.util.*;
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[] trucks = new int[n];
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) {
			trucks[i] = Integer.parseInt(st.nextToken());
		}
		Queue<Integer> q = new LinkedList<>();
		for(int i=0;i<w;i++) {
			q.offer(0);
		}
		int idx = 0;
		int time = 0;
		int weight = 0;
		while(idx<n) {
			time++;
			weight -= q.poll();
			if(weight + trucks[idx]<=l) {
				q.offer(trucks[idx]);
				weight += trucks[idx];
				idx++;
			}
			else q.offer(0);
		}
		time += w;
		System.out.println(time);
	}
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 1477 휴게소 세우기  (0) 2025.09.18
[BOJ] 백준 1253 좋다  (0) 2025.09.17
[BOJ] 백준 12100 2024 Easy  (0) 2025.09.17
[BOJ] 백준 11559 Puyo Puyo  (0) 2025.09.17
[BOJ] 백준 12015 가장 긴 증가하는 부분 수열 2  (0) 2025.09.17