Skip to content

Commit aa53f54

Browse files
Time: 303 ms (46.55%), Space: 92.1 MB (33.01%) - LeetHub
1 parent 7610ace commit aa53f54

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
public:
3+
long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {
4+
5+
6+
vector<pair<int,int>> v;
7+
8+
for(int i=0;i<nums1.size();i++)
9+
v.push_back({nums2[i],nums1[i]});
10+
11+
sort(v.rbegin(),v.rend());
12+
13+
long long ans = 0;
14+
long long currSum = 0;
15+
16+
priority_queue<int,vector<int>,greater<int>> pq;
17+
18+
for(int i=0;i<k-1;i++){
19+
currSum += v[i].second;
20+
pq.push(v[i].second);
21+
}
22+
23+
for(int i = k-1;i<nums1.size();i++){
24+
currSum += v[i].second;
25+
pq.push(v[i].second);
26+
ans = max(ans,currSum*v[i].first);
27+
28+
currSum -= pq.top();
29+
pq.pop();
30+
}
31+
32+
return ans;
33+
}
34+
};

0 commit comments

Comments
 (0)