Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- BOJ
- 문제풀이
- 문자열
- 백준
- 건강
- 알고리즘
- 러닝일지
- COS PRO
- Java
- 투포인터
- MySQL
- 문제해결
- DP
- binary search
- greedy
- SQL
- math
- db
- priorityqueue
- 시뮬레이션
- 코딩테스트
- 운동기록
- oracle
- SWEA
- 프로그래머스
- dfs
- BFS
- 이분탐색
- 코테
- 자바
Archives
- Today
- Total
슈콩
[BOJ] 백준 13335 트럭 본문
[문제]
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 |