Skip to content

Commit 8a826d6

Browse files
committed
[PGS] 디스크 컨트롤러(Python) / Level 3 / 60분 / 힌트, 성공
1 parent c069298 commit 8a826d6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import heapq
2+
3+
def solution(jobs):
4+
jobs.sort() # 요청시간 기준 정렬
5+
job_len = len(jobs)
6+
i = 0 # jobs 인덱스
7+
end_time = 0 # 현재 시간
8+
return_time = 0 # 작업 반환 시간
9+
count = 0 # 작업 처리한 개수
10+
11+
heap = []
12+
13+
while count < job_len:
14+
# 현재 시간에 요청된 작업 처리
15+
while i < job_len and jobs[i][0] <= end_time:
16+
heapq.heappush(heap, (jobs[i][1], jobs[i][0], i)) # 소요시간, 요청시간, 작업번호 순서
17+
i += 1
18+
19+
# 대기 큐에 작업이 있다면, 시간을 업데이트한다.
20+
if len(heap) > 0:
21+
work_time, start_time, num = heapq.heappop(heap)
22+
end_time += work_time
23+
return_time += end_time - start_time
24+
count += 1
25+
else:
26+
# 대기 큐가 비었다면, 다음 작업이 올 때까지 기다려야 한다.
27+
end_time = jobs[i][0]
28+
29+
return return_time // job_len

0 commit comments

Comments
 (0)