Skip to content

Commit

Permalink
Merge pull request #168 from AlgoLeadMe/8-wonjunYou
Browse files Browse the repository at this point in the history
8-wonjunYou
  • Loading branch information
wonjunYou authored Nov 22, 2024
2 parents 2cc0145 + 22f4706 commit ee775e3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions wonjunYou/구현/PRG_과제_진행하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def solution(plans):
stack = []
result = []

plans.sort(key=lambda x: x[1])

for i in range(len(plans) - 1):
current_start_time = plans[i][1]
next_start_time = plans[i + 1][1]

playtime_difference = calculateDifference(current_start_time, next_start_time)

if int(plans[i][2]) > playtime_difference:
stack.append([plans[i][0], int(plans[i][2]) - playtime_difference])
else:
result.append(plans[i][0])
remaining_time = playtime_difference - int(plans[i][2])

while stack and remaining_time > 0:
previous_task, previous_time = stack.pop()
if previous_time > remaining_time:
stack.append([previous_task, previous_time - remaining_time])
remaining_time = 0
else:
result.append(previous_task)
remaining_time -= previous_time

result.append(plans[-1][0])

while stack:
result.append(stack.pop()[0])

return result

def calculateDifference(current_time, next_time):
h1, m1 = map(int, current_time.split(":"))
h2, m2 = map(int, next_time.split(":"))

current_minutes = h1 * 60 + m1
next_minutes = h2 * 60 + m2

return next_minutes - current_minutes

0 comments on commit ee775e3

Please sign in to comment.