# Process SJF(Short Job First)
# 1. Input tasks [[input_time, task_time], ..]
# 2. Sort using input_time
# 3. Iterate till tasks is remained
# 3.1. Search shortest task which input time is under time spent
# 3.2. Do task and ++time
# 4. Return total time / initial length of tasks
import heapq
import math
def solution(tasks):
whole_task_time = 0
time_spent = 0
len_tasks = len(tasks)
# 2.
tasks_sorted = sorted(tasks, key=lambda k: (k[0]), reverse=False)
if len_tasks > 0:
# 3.
while len(tasks_sorted) > 0:
# 3.1.
current_input_time = tasks_sorted[0][0]
shortest_task_time = tasks_sorted[0][1]
index = 0
i = 1
if time_spent <current_input_time:
time_spent = current_input_time
while i < len(tasks_sorted) and tasks_sorted[i][0] <= time_spent:
if tasks_sorted[i][1] <= shortest_task_time:
index = i
shortest_task_time = tasks_sorted[i][1]
i += 1
working_task = tasks_sorted.pop(index)
# 3.2.
time_spent += working_task[1]
whole_task_time += (time_spent - (working_task[0]))
return math.floor(whole_task_time / len_tasks)
2020/10/07 - [Life/Item review] - Lenovo 레노보 씽크패드 Thinkpad 빨콩 무선키보드/블루투스/울트라나브2/트랙키보드 구매 후기
Lenovo 레노보 씽크패드 Thinkpad 빨콩 무선키보드/블루투스/울트라나브2/트랙키보드 구매 후기
빨콩 + 키감 + 무선 울트라나브2 를 기다리다가 최근 나왔길래 고민안하고 샀다. -> 가격 13만 5천원 내외였던 것 같은데 음.. 가성비는 그닥 -> 빨콩 예전 x1 이후에 간만에 빨콩을 쓰니 손이 잘 안
itdar.tistory.com
CodeSignal Intro Databases #7 MostExpensive. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그
CodeSignal Intro Databases #7 MostExpensive. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,cod..
itdar.tistory.com
Agile Software Engineering (You aren't gonna need it, Yagni) 소프트웨어 개발에서 고려되어야 할 부분 (야그니)
Origin ( Here ) 원본 ( 여기 ) 불필요한 개발을 늘리지 말자. 당장 필요한 메소드, 속성이 아니면 심플하게~ Yagni originally is an acronym that stands for "You Aren't Gonna Need It". It is a mantra f..
itdar.tistory.com