Skip to content

Commit 21c7ded

Browse files
Merge pull request #2063 from CodingTestStudy2/최민지
[최민지] Day20
2 parents 86b10e5 + 1e82e62 commit 21c7ded

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎leetcode3/최민지/857.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def mincostToHireWorkers(self, quality: list[int], wage: list[int], k: int) -> float:
3+
workers = []
4+
5+
for q, w in zip(quality, wage):
6+
workers.append((w / q, q))
7+
8+
workers.sort()
9+
10+
heap = []
11+
quality_sum = 0
12+
answer = float('inf')
13+
14+
for ratio, q in workers:
15+
heapq.heappush(heap, -q)
16+
quality_sum += q
17+
18+
if len(heap) > k:
19+
largest_q = -heapq.heappop(heap)
20+
quality_sum -= largest_q
21+
22+
if len(heap) == k:
23+
answer = min(
24+
answer,
25+
quality_sum * ratio
26+
)
27+
28+
return answer
29+

0 commit comments

Comments
 (0)