aboutsummaryrefslogtreecommitdiff
path: root/max_performance_team.cpp
diff options
context:
space:
mode:
authorjack <[email protected]>2024-06-14 13:13:15 -0600
committerjack <[email protected]>2024-06-14 13:13:15 -0600
commitd343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch)
tree96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /max_performance_team.cpp
downloadleetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz
leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip
initial
Diffstat (limited to 'max_performance_team.cpp')
-rw-r--r--max_performance_team.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/max_performance_team.cpp b/max_performance_team.cpp
new file mode 100644
index 0000000..07a6e6e
--- /dev/null
+++ b/max_performance_team.cpp
@@ -0,0 +1,33 @@
+#include "leetcode.h"
+
+class Solution {
+public:
+ const int mod = (int)1e9 + 7;
+ int maxPerformance(int n, vector<int> &speed, vector<int> &efficiency,
+ int k) {
+ priority_queue<int, vector<int>, greater<int>> pqvg;
+ vector<pair<int, int>> vp;
+ for (int i = 0; i < n; i++)
+ vp.push_back({efficiency[i], speed[i]});
+ sort(vp.rbegin(), vp.rend());
+ long totSpeed = 0, ans = 0;
+ for (int i = 0; i < n; i++) {
+ int currEff = vp[i].first, currSpeed = vp[i].second;
+ if (pqvg.size() == k) {
+ totSpeed -= pqvg.top();
+ pqvg.pop();
+ }
+ pqvg.push(currSpeed);
+ totSpeed += currSpeed;
+ ans = max(ans, totSpeed * currEff);
+ }
+ return ans % mod;
+ }
+};
+
+int main() {
+ Solution obj;
+ int n = 6, k = 2;
+ vector<int> speed = {2, 10, 3, 1, 5, 8}, efficiency = {5, 4, 3, 9, 7, 2};
+ cout << obj.maxPerformance(n, speed, efficiency, k);
+}