Skip to content

Commit 05d61d1

Browse files
Create 1383-Maximum-Performance-of-a-Team.cs
1 parent fd08e46 commit 05d61d1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
public class Solution {
2+
public class Engineer
3+
{
4+
public int speed;
5+
public int efficiency;
6+
public Engineer(int speed, int efficiency)
7+
{
8+
this.speed = speed;
9+
this.efficiency = efficiency;
10+
}
11+
12+
}
13+
14+
public int MaxPerformance(int n, int[] speed, int[] efficiency, int k)
15+
{
16+
List<Engineer> engineers = new();
17+
for (int i = 0; i < n; i++)
18+
{
19+
engineers.Add(new Engineer(speed[i], efficiency[i]));
20+
}
21+
22+
engineers = engineers.OrderByDescending(x => x.efficiency).ToList();
23+
var queue = new PriorityQueue<int, int>();
24+
long speedTotal = 0, result = 0;
25+
foreach (var engineer in engineers)
26+
{
27+
if (queue.Count > k - 1)
28+
speedTotal -= queue.Dequeue();
29+
queue.Enqueue(engineer.speed, engineer.speed);
30+
speedTotal += engineer.speed;
31+
result = Math.Max(result, speedTotal * engineer.efficiency);
32+
}
33+
34+
return (int)(result % 1000000007);
35+
}
36+
}

0 commit comments

Comments
 (0)