Skip to content

Commit

Permalink
programmers/python/level3/kakao/2018/1_shuttle_bust.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bong6981 committed Jun 12, 2022
1 parent be4614e commit fd91031
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions programmers/python/level3/kakao/2018/1_shuttle_bust.py
@@ -0,0 +1,100 @@
# https://programmers.co.kr/learn/courses/30/lessons/17678
from collections import deque

# def solution(n, t, m, timetable):
# ## start
# st = 60 * 9
# ## last_car
# lt = st + t * (n-1)

# crew = []
# for time in timetable:
# h, minute = map(int, time.split(":"))
# time = h * 60 + minute
# if time <= lt:
# crew.append(time)

# crew.sort()
# crew = deque(crew)


# ans = 0
# for i in range(1, n+1):
# if i == n:
# print(crew, len(crew), m)
# if len(crew) < m:
# ans = lt
# else:
# early_then = crew[m-1]
# ans = early_then - 1

# time = st + (i - 1) * t
# cnt = m
# while crew and crew[0] <= time and cnt > 0:
# crew.popleft()
# cnt -= 1

# h = str(ans // 60)
# m = str(ans % 60)
# ans = ''
# if len(h) == 1:
# ans += '0'
# ans += h
# ans += ':'
# if len(m) == 1:
# ans += '0'
# ans += m
# return ans


def solution(n, t, m, timetable):
## start
st = 60 * 9
## last_car
lt = st + t * (n-1)

crew = []
for time in timetable:
h, minute = map(int, time.split(":"))
time = h * 60 + minute
if time <= lt:
crew.append(time)

crew.sort()
print(crew)

ans = 0
crew_idx = 0
for i in range(1, n+1):
if i == n:
print(crew, crew_idx, (crew_idx + (m - crew_idx)-1), m)
if len(crew) - crew_idx < m:
ans = lt
else:
early_then = crew[crew_idx + m-1]
ans = early_then - 1
break

time = st + (i - 1) * t
cnt = m
while crew_idx < len(crew) and crew[crew_idx] <= time and cnt > 0:
crew_idx += 1
cnt -= 1

h = str(ans // 60)
m = str(ans % 60)
ans = ''
if len(h) == 1:
ans += '0'
ans += h
ans += ':'
if len(m) == 1:
ans += '0'
ans += m
return ans


# print(solution(1, 1, 5, ["08:00", "08:01", "08:02", "08:03"]))
print(solution(2, 10, 2, ["09:10", "09:09", "08:00"]))


0 comments on commit fd91031

Please sign in to comment.