Level 2
https://school.programmers.co.kr/learn/courses/30/lessons/155651
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
import heapq
def chg_time(x, s):
h, m = map(int, x.split(":"))
if s: #체크아웃
if m+10 >= 60: #청소기간 더해주기
h+=1
m-=50
else:
m+=10
return h*100+m
def solution(book_time):
answer = 0
book_time.sort() #정렬
outQ = [0]
for i, o in book_time:
iTime = chg_time(i, False)
oTime = chg_time(o,True)
if iTime >= outQ[0]: #체크인시간이 제일 빠른 체크아웃 시간보다 늦거나 같은 경우
heapq.heappop(outQ)
heapq.heappush(outQ, oTime)
answer = max(answer, len(outQ))
return answer
최소 객실 수를 구하는 문제로 heapq를 사용해주었다.
반응형
'IT > 알고리즘' 카테고리의 다른 글
[백준 Python] 2696번 중앙값 구하기 (0) | 2025.02.23 |
---|---|
[백준 Python] 1717번 집합의 표현 (0) | 2025.02.21 |
[백준 Python] 1958번 LCS 3 (0) | 2025.02.17 |
[백준 Python] 14503번 로봇 청소기 (0) | 2025.02.13 |
[백준 Python] 14728번 벼락치기 (0) | 2025.02.11 |