Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26c7d13

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /