Skip to content

Commit 1981ce2

Browse files
committed
[Gold V] Title: 배, Time: 260 ms, Memory: 16476 KB -BaekjoonHub
1 parent 6b36f00 commit 1981ce2

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

백준/Gold/1092. 배/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Gold V] 배 - 1092
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1092)
4+
5+
### 성능 요약
6+
7+
메모리: 16476 KB, 시간: 260 ms
8+
9+
### 분류
10+
11+
그리디 알고리즘, 정렬
12+
13+
### 제출 일자
14+
15+
2025년 8월 30일 19:20:10
16+
17+
### 문제 설명
18+
19+
<p>지민이는 항구에서 일한다. 그리고 화물을 배에 실어야 한다. 모든 화물은 박스에 안에 넣어져 있다. 항구에는 크레인이 N대 있고, 1분에 박스를 하나씩 배에 실을 수 있다. 모든 크레인은 동시에 움직인다.</p>
20+
21+
<p>각 크레인은 무게 제한이 있다. 이 무게 제한보다 무거운 박스는 크레인으로 움직일 수 없다. 모든 박스를 배로 옮기는데 드는 시간의 최솟값을 구하는 프로그램을 작성하시오.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에는 각 크레인의 무게 제한이 주어진다. 이 값은 1,000,000보다 작거나 같다. 셋째 줄에는 박스의 수 M이 주어진다. M은 10,000보다 작거나 같은 자연수이다. 넷째 줄에는 각 박스의 무게가 주어진다. 이 값도 1,000,000보다 작거나 같은 자연수이다.</p>
26+
27+
### 출력
28+
29+
<p>첫째 줄에 모든 박스를 배로 옮기는데 드는 시간의 최솟값을 출력한다. 만약 모든 박스를 배로 옮길 수 없으면 -1을 출력한다.</p>
30+

백준/Gold/1092. 배/배.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws IOException{
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
8+
int N = Integer.parseInt(br.readLine());
9+
List<Integer> crane = new ArrayList<>();
10+
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
for(int i = 0; i<N; i++)
13+
crane.add(Integer.parseInt(st.nextToken()));
14+
15+
int M = Integer.parseInt(br.readLine());
16+
List<Integer> box = new ArrayList<>();
17+
18+
st = new StringTokenizer(br.readLine());
19+
for(int i = 0; i<M; i++)
20+
box.add(Integer.parseInt(st.nextToken()));
21+
22+
//내림차순으로 정렬
23+
crane.sort(Collections.reverseOrder());
24+
box.sort(Collections.reverseOrder());
25+
26+
if(crane.get(0)<box.get(0)){
27+
System.out.println(-1);
28+
return;
29+
}
30+
31+
int day = 0;
32+
while(!box.isEmpty()){
33+
int boxIdx = 0, craneIdx = 0;
34+
35+
while(craneIdx<N){
36+
if(boxIdx == box.size())
37+
break;
38+
else if(crane.get(craneIdx) >= box.get(boxIdx)){
39+
box.remove(boxIdx);
40+
craneIdx++;
41+
}
42+
else
43+
boxIdx++;
44+
}
45+
46+
day++;
47+
}
48+
49+
System.out.println(day);
50+
}
51+
}

0 commit comments

Comments
 (0)