From f5e5fa975d69ea71da2c369aa170d46f83b9b06d Mon Sep 17 00:00:00 2001 From: Jisan <149364697+kjs254@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:58:52 +0900 Subject: [PATCH] 3-kjs254 --- kjs254/README.md | 1 + ...4\204\353\241\234\354\204\270\354\212\244.py" | 0 ...\274\352\267\274 \354\247\200\354\210\230.py" | 16 ++++++++++++++++ 3 files changed, 17 insertions(+) rename "kjs254/\355\201\220/2-kjs254" => "kjs254/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.py" (100%) create mode 100644 "kjs254/\355\236\231/\354\225\274\352\267\274 \354\247\200\354\210\230.py" diff --git a/kjs254/README.md b/kjs254/README.md index d8df057..620af80 100644 --- a/kjs254/README.md +++ b/kjs254/README.md @@ -4,4 +4,5 @@ |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2024.02.12 | 스택 | [기능개발](https://school.programmers.co.kr/learn/courses/30/lessons/42586) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/2) | | 2차시 | 2024.02.15 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/6) | +| 3차시 | 2024.02.15 | 힙 | [야근 지수](https://school.programmers.co.kr/learn/courses/30/lessons/12927) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/10) | --- diff --git "a/kjs254/\355\201\220/2-kjs254" "b/kjs254/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.py" similarity index 100% rename from "kjs254/\355\201\220/2-kjs254" rename to "kjs254/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.py" diff --git "a/kjs254/\355\236\231/\354\225\274\352\267\274 \354\247\200\354\210\230.py" "b/kjs254/\355\236\231/\354\225\274\352\267\274 \354\247\200\354\210\230.py" new file mode 100644 index 0000000..74c1573 --- /dev/null +++ "b/kjs254/\355\236\231/\354\225\274\352\267\274 \354\247\200\354\210\230.py" @@ -0,0 +1,16 @@ +import heapq +def solution(n, works): + max_heap = [] + for w in works: + heapq.heappush(max_heap, (-w,w)) + + for i in range(n): + max_work = heapq.heappop(max_heap)[1]-1 + if max_work<0: + return 0 + + heapq.heappush(max_heap,(-max_work,max_work)) + + print(max_heap) + answer = sum([x[1]**2 for x in max_heap]) + return answer \ No newline at end of file