human
I found an interesting problem on https://leetcode.com/problems/minimum-cost-to-hire-k-workers/:
There are N workers.  The i-th worker has a quality[i] and a minimum wage expectation wage[i].
Now we want to hire exactly K workers to form a paid group.  When hiring a group of K workers, we must pay them according to the following rules:

Every worker in the paid group should be paid in the ratio of their quality compared to other workers in the paid group.
Every worker in the paid group must be paid at least their minimum wage expectation.

Return the least amount of money needed to form a paid group satisfying the above conditions.
 


Example 1:
Input: quality = [10,20,5], wage = [70,50,30], K = 2
Output: 105.00000
Explanation: We pay 70 to 0-th worker and 35 to 2-th worker.

Example 2:
Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], K = 3
Output: 30.66667
Explanation: We pay 4 to 0-th worker, 13.33333 to 2-th and 3-th workers seperately. 

 
Note:

1 <= K <= N <= 10000, where N = quality.length = wage.length
1 <= quality[i] <= 10000
1 <= wage[i] <= 10000
Answers within 10^-5 of the correct answer will be considered correct.

I tried it in Python, but could not do it. Can you solve it?

=====
Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

import heapq
class Solution:
    def mincostToHireWorkers(self, quality: List[int], wage: List[int], K: int) -> float:
        n_workers = len(wage)
        pairs = [None]*n_workers # (quality, ratio) 
        for i in range(n_workers): 
            pairs[i] = (quality[i], wage[i]/quality[i])

        pairs = sorted(pairs, key=lambda x: (x[1])) # sort dec by ratio 
        
        # ...incorrect solution...
        # max_q = pairs[i:i+K]
        # for i in range(n_workers-K+1):
            # min_cost = min(min_cost, self.cost(pairs[i:i+K]))
        
        sum_q = sum([p[0] for p in pairs[0:K]])
        maxheap_q = [-p[0] for p in pairs[0:K]] # use minus to create max heap
        heapq.heapify(maxheap_q) 
        min_cost = sum_q * pairs[K-1][1]
        
        for i in range(K, n_workers):
            sum_q = sum_q - (-heapq.heappop(maxheap_q)) + pairs[i][0]
            min_cost = min(min_cost, sum_q * pairs[i][1])
            heapq.heappush(maxheap_q, -pairs[i][0]) # push minus value to max heap
            
        return min_cost