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.
Input: quality = [10,20,5], wage = [70,50,30], K = 2
Explanation: We pay 70 to 0-th worker and 35 to 2-th worker.
Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], K = 3
Explanation: We pay 4 to 0-th worker, 13.33333 to 2-th and 3-th workers seperately.
- 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个人的钱为p[i]，则对于被选上的K个人来说，都有相同的比例 p[i] / quality[i]（根据条件1）
- 也就是说一旦我们选定了比例 r，那么最后选的K个人一定都满足 r * quality[i] > wage[i]（因为已经被选上了自然满足条件2）
- 上式逆推为 r > (wage/quality),故我们将所有人按照 wage/quality 的大小排序，依次作为r 来判断最后的总价格。