1383. Maximum Performance of a Team
Question
You are given two integers
n
andk
and two integer arraysspeed
andefficiency
both of lengthn
. There aren
engineers numbered from1
ton
.speed[i]
andefficiency[i]
represent the speed and efficiency of thei<sup>th</sup>
engineer respectively.Choose at most
k
different engineers out of then
engineers to form a team with the maximum performance.The performance of a team is the sum of their engineers’ speeds multiplied by the minimum efficiency among their engineers.
Return the maximum performance of this team. Since the answer can be a huge number, return it modulo
10<sup>9</sup><span> </span>+ 7
.
Solution
排序,将所有工程师根据其效率降序排列。
此时遍历时后一个工程师的效率一定小于等于前一个工程师。
因此,此时遍历到每一个工程师,其前面所有的工程师的efficiency均大于等于其本身。
维护一个所有选取工程师的总速度ttSpd,每次计算并更新max的值。
用最小堆来维护选取的工程师速度,如果优先级队列的尺寸超过k-1,则poll掉队列内最低的速度。
Code
1 | class Solution { |
1383. Maximum Performance of a Team
https://xuanhe95.github.io/2022/09/11/1383-Maximum-Performance-of-a-Team/