Skip to content

Commit f8692d6

Browse files
committed
92차 3번 문제 다시 풀이
1 parent ad95a22 commit f8692d6

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

live9/test92/문제3/박희경.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import heapq
22

33
def solution(book_time):
4-
answer = 0
5-
# book_time.sort()
6-
7-
def change_minute(time):
4+
5+
def hour_to_minute(time):
86
h, m = map(int, time.split(":"))
97
return h * 60 + m
108

11-
heap = list([change_minute(start), change_minute(end) + 10] for start, end in book_time)
12-
# [[850, 1160], [860, 920], [900, 1020], [1000, 1100], [1100, 1280]]
9+
book = sorted(list([hour_to_minute(start), hour_to_minute(end) + 10] for start, end in book_time))
1310

14-
heapq.heapify(heap)
15-
print(heap)
11+
room = []
12+
for start, end in book:
13+
# 현재 예약 시작 시간보다 가장 빨리 퇴실 시간 + 10분보다 이후라면 예약 가능 (갱신)
14+
if room and start >= room[0]:
15+
heapq.heappop(room)
1616

17-
while heap:
18-
start, end = heap[0]
19-
print(heap)
20-
next_start, next_end = heapq.heappop(heap)
21-
if start <= next_start <= end:
22-
answer += 1
23-
start = next_start
24-
end = next_end
25-
else:
26-
break
17+
# 현재 예약 종료 시간을 힙에 추가 (새로운 방 사용)
18+
heapq.heappush(room, end)
2719

28-
29-
return answer
20+
return len(room)

0 commit comments

Comments
 (0)