Using priority queue and set only! Simple understandable code
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        priority_queue
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<pair<long long,int>>> pq;\n        int n = nums.size();\n        for(int i=0;i<n;i++){\n            pq.push({nums[i],i});\n        }\n        unordered_set<int> st;\n        long long res = accumulate(nums.begin(),nums.end(),0LL);\n        vector<long long> ans;\n        \n        for(int i=0;i<queries.size();i++){\n            \n            int idx = queries[i][0];\n            int num = queries[i][1];\n            if(st.find(idx)==st.end()){\n                st.insert(idx);\n                res -= nums[idx];\n            }\n            while(!pq.empty()&&num>0){\n                long long val = pq.top().first;\n                int index = pq.top().second;\n                pq.pop();\n                if(st.find(index)!=st.end()) continue;\n                else{\n                    st.insert(index);\n                    res-=nums[index];\n                    num--;\n                }\n            }\n            ans.push_back(res);\n        }\n        return ans;\n    }\n};\n```
['C++']