Skip to content

Commit 7bb55a0

Browse files
authored
Merge pull request chipbk10#99 from chipbk10/Heap
Solve Problem 1383 - Maximum Performance of a team
2 parents 0da9bdb + 12a83f9 commit 7bb55a0

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

TipsAndTricks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Store currently unsolved elements, later if there is a bigger number, withdraw t
1717
- initiate UF when doing union (using Map) [947](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/discuss/197668/Count-the-Number-of-Islands-O(N)
1818
- how to guess an element from a set? [843](https://leetcode.com/problems/guess-the-word/discuss/160945/Python-O(n)-with-maximum-overlap-heuristic)
1919
- circular array. Avoid the circular point by working on 2 intervals `[0..n-1)` && `[1..n)` [213](), [1388]()
20+
- using XOR (identical = 0, different = 1) to check duplicated elements in array [136]()
2021

src/contest/ReadMe.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public class ReadMe {
88
// graph: 997[v] 1361[v] 1043[v] 1387[~]
99
// dfs: 1319[v] 1254[v] 1377[v] 1145[x]
1010
// bfs: 1345[v] 1368[!] 1311[v] 1293[x]
11-
// backtrack: 1307[!] 1239[v] 1219[v] 1291
12-
// dp: 1349[!] 1340[v] 1367[v] 1388
13-
// divide & conquer: 932[!] 514 903[v] 327
14-
// greedy: 1354[!] 1353[x] 1338[v] 1383
11+
// backtrack: 1307[!] 1239[v] 1219[v] 1291[~]
12+
// dp: 1349[!] 1340[v] 1367[v] 1388[!]
13+
// divide & conquer: 932[!] 514 903[v] 327[x]
14+
// greedy: 1354[!] 1353[x] 1338[v] 1383[!]
1515
// stack: 1190[!] 975[x] 1381[v] 901
1616
// binary search: 1351[v] 1337[v] 1292[!] 1235
1717
// 2 pointers: 1248[*] 1234[v] 986[v] 826
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package heap;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class Problem1383_MaximumPerformanceOfTeam {
6+
7+
public int maxPerformance(int n, int[] speed, int[] efficiency, int k) {
8+
// sum(speed) * min(efficiency)
9+
// k engineers
10+
11+
PriorityQueue<Integer> effQueue = new PriorityQueue<>((i,j) -> efficiency[j] - efficiency[i]);
12+
for (int i = 0; i < n; i++) effQueue.offer(i);
13+
14+
long sum = 0, res = 0;
15+
PriorityQueue<Integer> spQueue = new PriorityQueue<>();
16+
while (!effQueue.isEmpty()) {
17+
int i = effQueue.poll();
18+
spQueue.offer(speed[i]);
19+
sum += speed[i];
20+
if (spQueue.size() > k) {
21+
sum -= spQueue.poll();
22+
}
23+
res = Math.max(res, sum * efficiency[i]);
24+
}
25+
return (int) (res % (long)(1e9 + 7));
26+
}
27+
28+
}

0 commit comments

Comments
 (0)