forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1383-Maximum-Performance-Of-A-Team.cs
36 lines (32 loc) · 1.14 KB
/
1383-Maximum-Performance-Of-A-Team.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class Solution {
public class Engineer
{
public int speed;
public int efficiency;
public Engineer(int speed, int efficiency)
{
this.speed = speed;
this.efficiency = efficiency;
}
}
public int MaxPerformance(int n, int[] speed, int[] efficiency, int k)
{
List<Engineer> engineers = new();
for (int i = 0; i < n; i++)
{
engineers.Add(new Engineer(speed[i], efficiency[i]));
}
engineers = engineers.OrderByDescending(x => x.efficiency).ToList();
var queue = new PriorityQueue<int, int>();
long speedTotal = 0, result = 0;
foreach (var engineer in engineers)
{
if (queue.Count > k - 1)
speedTotal -= queue.Dequeue();
queue.Enqueue(engineer.speed, engineer.speed);
speedTotal += engineer.speed;
result = Math.Max(result, speedTotal * engineer.efficiency);
}
return (int)(result % 1000000007);
}
}