There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wage expectation for the ith worker.
We want to hire exactly k workers to form a paid group. To hire a group of k workers, we must pay them according to the following rules:
Given the integer k, return the least amount of money needed to form a paid group satisfying the above conditions. Answers within 10-5 of the actual answer will be accepted.
Input: quality = [10,20,5], wage = [70,50,30], k = 2
Output: 105.00000
Explanation: We pay 70 to 0th worker and 35 to 2nd worker.
Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3
Output: 30.66667Explanation: We pay 4 to 0th worker, 13.33333 to 2nd and 3rd workers separately.
The problem of hiring K workers at the minimum cost can be broken down into finding the optimal group of K workers such that the ratio (quality to wage ratio) aligns across all selected workers. This can be achieved by evaluating all possible combinations of K workers, which although infeasible for large inputs, provides a necessary understanding of the problem structure.
To hire K workers while minimizing the cost, consider the smallest ratio of wage-to-quality and always select the lowest quality workers to achieve optimal cost. By applying a max-heap on quality, we can evaluate the minimal ratios while keeping control over the maximum quality sum to pay the minimal cost.