Class Solution
java.lang.Object
g0801_0900.s0857_minimum_cost_to_hire_k_workers.Solution
857 - Minimum Cost to Hire K Workers.<p>Hard</p>
<p>There are <code>n</code> workers. You are given two integer arrays <code>quality</code> and <code>wage</code> where <code>quality[i]</code> is the quality of the <code>i<sup>th</sup></code> worker and <code>wage[i]</code> is the minimum wage expectation for the <code>i<sup>th</sup></code> worker.</p>
<p>We want to hire exactly <code>k</code> workers to form a paid group. To hire a group of <code>k</code> workers, we must pay them according to the following rules:</p>
<ol>
<li>Every worker in the paid group should be paid in the ratio of their quality compared to other workers in the paid group.</li>
<li>Every worker in the paid group must be paid at least their minimum wage expectation.</li>
</ol>
<p>Given the integer <code>k</code>, return <em>the least amount of money needed to form a paid group satisfying the above conditions</em>. Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> quality = [10,20,5], wage = [70,50,30], k = 2</p>
<p><strong>Output:</strong> 105.00000</p>
<p><strong>Explanation:</strong> We pay 70 to 0<sup>th</sup> worker and 35 to 2<sup>nd</sup> worker.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3</p>
<p><strong>Output:</strong> 30.66667</p>
<p><strong>Explanation:</strong> We pay 4 to 0<sup>th</sup> worker, 13.33333 to 2<sup>nd</sup> and 3<sup>rd</sup> workers separately.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == quality.length == wage.length</code></li>
<li><code>1 <= k <= n <= 10<sup>4</sup></code></li>
<li><code>1 <= quality[i], wage[i] <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
mincostToHireWorkers
public double mincostToHireWorkers(int[] quality, int[] wage, int k)
-