Skip to content

Commit 26c7d13

Browse files
authored
Create 1383. Maximum Performance of a Team
1 parent 53d63bc commit 26c7d13

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

1383. Maximum Performance of a Team

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public int maxPerformance(int n, int[] s, int[] e, int k) {
3+
4+
long MOD = 1_000_000_007;
5+
int[][] pair = new int[n][2];
6+
for(int i = 0; i < n; i++) {
7+
pair[i][0] = e[i];
8+
pair[i][1] = s[i];
9+
}
10+
11+
Arrays.sort(pair, (a,b) -> b[0]-a[0]);
12+
13+
PriorityQueue<Integer> speed = new PriorityQueue<>();
14+
15+
long speedSum = 0, maxPerformance = 0;
16+
17+
for(int[] p : pair) {
18+
speedSum+=p[1];
19+
speed.offer(p[1]);
20+
if(speed.size() > k) {
21+
speedSum-=speed.poll();
22+
}
23+
maxPerformance = Math.max(maxPerformance, speedSum*p[0]);
24+
}
25+
26+
return (int)(maxPerformance%MOD);
27+
28+
}
29+
}

0 commit comments

Comments
 (0)