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
- 코딩테스트
- SWEA
- MySQL
- 시뮬레이션
- dfs
- binary search
- BFS
- 운동기록
- greedy
- priorityqueue
- SQL
- Java
- 코테
- 프로그래머스
- 투포인터
- DP
- db
- math
- 문제풀이
- 자바
- 이분탐색
- 백준
- BOJ
- COS PRO
- oracle
- 알고리즘
- 건강
- 문자열
- 러닝일지
- 문제해결
Archives
- Today
- Total
슈콩
[BOJ] 백준 8980 택배 본문
[문제]
https://www.acmicpc.net/problem/8980
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static class Deliver{
int from,to,box;
Deliver(int from,int to,int box){
this.from = from;
this.to = to;
this.box = box;
}
}
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[] truck = new int[n+1];
int c = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(br.readLine());
List<Deliver> list = new ArrayList<>();
for(int i=0;i<m;i++) {
st = new StringTokenizer(br.readLine());
int from = Integer.parseInt(st.nextToken());
int to = Integer.parseInt(st.nextToken());
int box = Integer.parseInt(st.nextToken());
list.add(new Deliver(from,to,box));
}
list.sort((a,b)->{
return a.to - b.to;
});
int result = 0;
for(Deliver d : list) {
int canLoad = d.box;
for(int i=d.from;i<d.to;i++) {
canLoad = Math.min(canLoad, c - truck[i]);
}
if(canLoad>0) {
for(int i=d.from;i<d.to;i++) {
truck[i] += canLoad;
}
}
result += canLoad;
}
System.out.println(result);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 6064 카잉 달력 (0) | 2025.09.05 |
|---|---|
| [BOJ] 백준 11653 소인수분해 (0) | 2025.09.05 |
| [BOJ] 백준 7570 줄 세우기 (0) | 2025.09.04 |
| [BOJ] 백준 2457 공주님의 정원 (0) | 2025.09.04 |
| [BOJ] 백준 2457 공주님의 정원 (0) | 2025.09.03 |