We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fb42682 commit cfbda22Copy full SHA for cfbda22
kojungbeom/Programmers/Level3/야근 지수.py
@@ -0,0 +1,20 @@
1
+import heapq
2
+def solution(n, works):
3
+ # n: 남은 시간
4
+ # works: 각 일에 대한 작업량을 나타낸 array
5
+ # 야근피로도 = 야근 시작 시점에서 남은 일의 작업량을 제곱해서 더한것
6
+ # works의 길이가 20,000 미만이니까.. O(n**2)까지도 Okay..?
7
+ # 매번 정렬해야지 생각하고도 heap을 떠올리지못한 나를 탓하라.
8
+ answer = 0
9
+ works2 = [-w for w in works]
10
+ heapq.heapify(works2)
11
+
12
+ while n > 0:
13
+ value = heapq.heappop(works2)
14
+ if value != 0:
15
+ value += 1
16
+ n -= 1
17
+ heapq.heappush(works2, value)
18
19
+ answer = sum([(w * -1) ** 2 for w in works2])
20
+ return answer
0 commit comments