Today Sangmin Learned
728x90

1. 링크

https://www.acmicpc.net/problem/1092

2. 난이도(solved.ac 참고)

골드5

3. 풀이

# https://www.acmicpc.net/problem/1092
import sys
input = sys.stdin.readline
n = int(input())
weight = sorted(list(map(int, input().split())), reverse=True)
m = int(input())
box = sorted(list(map(int, input().split())), reverse=True)
time = 0
if max(box) > max(weight):
print(-1)
else:
while len(box) > 0:
time += 1
for i in range(len(weight)):
for j in range(len(box)):
if weight[i] >= box[j]:
box.pop(j)
break
print(time)
view raw 배.py hosted with ❤ by GitHub

가장 높은 중량을 들 수 있는 크레인에 가장 무거운 박스를 배치하면 된다. 크레인에 대한 반복문이 끝나면 1회 순회한 것이므로 while문 직후에 time이라는, 우리가 답으로 출력할 변수의 값을 1씩 증가해준다. 그리고 크레인의 값이 더 클 경우에 break을 함으로써 weight에 대해 불필요하게 남은 box에 대한 반복문을 돌 필요가 없게끔 하였다(break없이 돌면 안돼서 넣은 것이기도 함).

profile

Today Sangmin Learned

@steadily-worked

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!