-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3080.cpp
More file actions
34 lines (34 loc) · 1 KB
/
3080.cpp
File metadata and controls
34 lines (34 loc) · 1 KB
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
typedef pair<int, int> P;
class Solution {
public:
vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {
long long sum = 0;
vector<long long> res;
int n = nums.size();
vector<bool> marked(n, false);
priority_queue<P, vector<P>, greater<P>> pq;
for (int i = 0; i < n; ++i) {
sum += nums[i];
pq.push({nums[i], i});
}
for (auto query : queries) {
if (!marked[query[0]]) {
marked[query[0]] = true;
sum -= nums[query[0]];
}
int cnt = query[1];
while (cnt && !pq.empty()) {
auto p = pq.top();
pq.pop();
int value = p.first;
int index = p.second;
if (marked[index]) continue;
marked[index] = true;
sum -= value;
cnt--;
}
res.push_back(sum);
}
return res;
}
};