1092 배

정민용·2023년 4월 22일

백준

목록 보기
143/286

문제

지민이는 항구에서 일한다. 그리고 화물을 배에 실어야 한다. 모든 화물은 박스에 안에 넣어져 있다. 항구에는 크레인이 N대 있고, 1분에 박스를 하나씩 배에 실을 수 있다. 모든 크레인은 동시에 움직인다.

각 크레인은 무게 제한이 있다. 이 무게 제한보다 무거운 박스는 크레인으로 움직일 수 없다. 모든 박스를 배로 옮기는데 드는 시간의 최솟값을 구하는 프로그램을 작성하시오.

# 1092
import sys
input = lambda: sys.stdin.readline().strip()

n = int(input())
crane = list(map(int, input().split()))
crane.sort(reverse = True)

m = int(input())
box = list(map(int, input().split()))
box.sort(reverse = True)

if box[0] > crane[0]:
    print("-1")
    exit(0)

time = 0
while len(box) > 0:
    for c in crane:
        for b in box:
            if b <= c:
                box.remove(b)
                break
    time += 1
        
print(time)

백준 1092 배

0개의 댓글