From 94e034c6e1029dd58debaf83477c988055afccef Mon Sep 17 00:00:00 2001 From: JSPark <48265129+pknujsp@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:51:08 +0900 Subject: [PATCH] 2024-03-19 --- pknujsp/README.md | 3 ++- ...50\355\212\270\353\241\244\353\237\254.py" | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 "pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py" diff --git a/pknujsp/README.md b/pknujsp/README.md index 6859f496..a5585860 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -39,4 +39,5 @@ | 35차시 | 2024.02.18 | 그리디 | [선물할인](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) | | 36차시 | 2024.02.21 | 이진탐색 | [휴게소 세우기](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) | | 37차시 | 2024.03.04 | 구현 | [n+1 카드게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) | -| 38차시 | 2024.03.08 | BRUTE_FORCE | [자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) | \ No newline at end of file +| 38차시 | 2024.03.08 | BRUTE_FORCE | [자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) | +| 39차시 | 2024.03.19 | 큐 | [디스크 컨트롤러](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) | \ No newline at end of file diff --git "a/pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py" "b/pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py" new file mode 100644 index 00000000..0a0b4d8e --- /dev/null +++ "b/pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py" @@ -0,0 +1,24 @@ +from heapq import * +from collections import * + +def solution(jobs): + jobs = deque(sorted(jobs)) + jobs_num = len(jobs) + + curr_time = wait_time = 0 + heap = [] + + while heap or jobs: + while jobs and jobs[0][0] <= curr_time: + requested_time, duration = jobs.popleft() + heappush(heap, (duration, requested_time)) + + if heap: + duration, requested_time = heappop(heap) + + curr_time += duration + wait_time += curr_time - requested_time + else: + curr_time += 1 + + return wait_time // jobs_num \ No newline at end of file