Untitled
unknown
c_cpp
2 years ago
466 B
14
Indexable
int getMinimumCost(vector<int> a, vector<int> b, int m) {
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
vector<int> ctr(a.size(), 1);
for (int i=0; i<a.size(); i++) {
pq.push({a[i], i});
}
int ans = 0;
while(m--) {
auto pi = pq.top();
pq.pop();
ans += pi.first;
int i = pi.second;
pq.push({a[i] + ctr[i]*b[i], i});
ctr[i]++;
}
return ans;
}Editor is loading...
Leave a Comment