[백준] 1092 : 배 - Python

Chooooo·2023년 1월 31일
0

알고리즘/백준

목록 보기
33/182
post-thumbnail

import sys
sys.stdin = open("input.text", "rt")
input = sys.stdin.readline

N = int(input())
limit = list(map(int, input().split()))
M = int(input())
data = list(map(int, input().split()))


limit.sort(reverse = True)
data.sort(reverse = True)
res = 0

if limit[0] < data[0]:
    print(-1)
else:
    while len(data) > 0:
        for crane in limit:
            for i in range(len(data)):
                if crane >= data[i]:
                    data.pop(i)
                    break
        res += 1
    
    print(res)

🎃 코멘트
크레인, 박스 무게제한 존재. 둘 다 내림차순으로 정렬한 후에 옮길 수 있는 것들부터 꺼낸다는 생각 할 수 있었어야 했다. 해당 박스를 담을 수 있다면 계속 제거하는 형식. 반복문 한번 돌 때마다 res += 1을 해줘서 카운트를 증가시킨다.

sys.stdin.readline을 input에 넣어서 속도 향상을 시키면 시간초과가 뜨지 않는다.

profile
back-end, 지속 성장 가능한 개발자를 향하여

0개의 댓글