forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1383.cpp
More file actions
34 lines (24 loc) · 873 Bytes
/
1383.cpp
File metadata and controls
34 lines (24 loc) · 873 Bytes
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
class Solution {
public:
int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) {
vector<pair<int, int>> com;
for(int i = 0; i < n; i++)
com.push_back({efficiency[i], speed[i]});
sort(com.rbegin(), com.rend());
priority_queue<int> pq;
long totalSpeed = 0, best = 0;
long long int MOD = 1e9 + 7;
for (auto& c : com) {
int curr_speed = c.second;
pq.push(-curr_speed);
if (pq.size() <= k)
totalSpeed += curr_speed;
else {
totalSpeed += curr_speed + pq.top();
pq.pop();
}
best = max(best, totalSpeed * c.first);
}
return (best % MOD);
}
};