https://school.programmers.co.kr/learn/courses/30/lessons/176962
from collections import deque
def solution(plans):
answer = []
q = deque()
for i in range(len(plans)):
# 시간을 분으로 변환 = 시간 * 60 + 분
time = plans[i][1].split(':')
new_time = int(time[0]) * 60 + int(time[1])
plans[i][1] = new_time
plans = sorted(plans, key=lambda x: x[1])
# 시간 순으로 정렬
for i in range(0, len(plans)-1):
work = plans[i]
next_work = plans[i+1]
done_time = int(work[1]) + int(work[2])
diff_time = next_work[1] - done_time
if diff_time < 0:
left_hour = abs(diff_time)
work[2] = left_hour
q.append(work)
else:
answer.append(work[0])
if q:
while diff_time > 0 and q:
left_work = q.pop()
diff_time -= left_work[2]
if diff_time < 0:
left_work[2] = abs(diff_time)
q.append(left_work)
elif diff_time == 0:
answer.append(left_work[0])
else:
answer.append(left_work[0])
if i == len(plans) - 2:
answer.append(plans[i+1][0])
while q:
q_work = q.pop()
answer.append(q_work[0])
return answer
# arr = [["science", "12:40", "50"], ["music", "12:20", "40"],
# ["history", "14:00", "30"], ["computer", "12:30", "100"]]
# arr = [["aaa", "12:00", "20"], ["bbb", "12:10", "30"], ["ccc", "12:40", "10"]]
arr = [["korean", "11:40", "30"], [
"english", "12:10", "20"], ["math", "12:30", "40"]]
print(solution(arr))
데큐를 이용한 구현 문제였다.