1092번: 배
첫째 줄에 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에는 각 크레인의 무게 제한이 주어진다. 이 값은 1,000,000보다 작거나 같다. 셋째 줄에는 박스의 수 M이 주어진다. M은 10,000보
www.acmicpc.net
# 배
# https://www.acmicpc.net/problem/1092 (탐욕)
# boxes : [8, 8, 4, 2, 2]
# cranes : [ 6, 9, 8 ]
# crane_queue: [[4, 2], [8, 2], [8]]
def run(cranes, boxes):
boxes.sort(reverse=True) # ((큰 박스 순서대로 선택해서)) 처리한다
crane_queue = [[] for _ in range(N)]
for box in boxes:
# 작업 가능 크레인 확인
idxes = [i for i, crane in enumerate(cranes) if crane >= box]
if len(idxes) == 0:
return -1
# 대기열이 작은 크레인 확인
idx, min_v = -1, 1e9
for i in idxes:
if len(crane_queue[i]) < min_v:
min_v = len(crane_queue[i])
idx = i
# 해당 크레인에 작업 할당
crane_queue[idx].append(box)
res = max([len(x) for x in crane_queue])
return res
N = int(input())
cranes = list(map(int, input().split()))
M = int(input())
boxes = list(map(int, input().split()))
ans = run(cranes, boxes)
print(ans)
'BOJ 알고리즘 (패캠) > 탐욕, 백트래킹' 카테고리의 다른 글
1461번: 도서관 (탐욕) (0) | 2020.10.23 |
---|---|
2212번: 센서 (탐욕) (0) | 2020.10.23 |
2012번: 등수 매기기 (탐욕) (0) | 2020.10.23 |
1439번: 뒤집기 (탐욕) (0) | 2020.10.22 |
5585번: 거스름돈 (탐욕) (0) | 2020.10.22 |