Easy to understand | Priority Queue Solution
Intuition\n\nWe will push elements in priority queue as pair of {element,index} and then we will mark the index given for each query index and if it is already 
# Intuition\n\nWe will push elements in priority queue as pair of `{element,index}` and then we will mark the index given for each query index and if it is already marked then we will not decrease our sum else we will decrease the sum and after processing each query we will `push_back` the remaining sum in `ans` array\n\n# Complexity\n- Time complexity: $$O(m*log(n) + n*log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(2*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\ntypedef pair<long long, int> P;\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        vector<bool> mark(nums.size(),false);\n        priority_queue<P, vector<P>, greater<P>> pq;\n        long long sum = 0;\n        vector<long long> ans;\n        for(int i=0; i<nums.size(); i++) {\n            sum += nums[i];\n            pq.push({nums[i],i});\n        }\n\n        for(auto &it : queries) {\n            int start = it[0];\n            int cnt = it[1];\n            if(mark[start] == false) {\n                mark[start] = true;\n                sum -= nums[start];\n                // cnt--;\n            }\n\n            while(!pq.empty() && cnt) {\n                auto pick = pq.top();\n                pq.pop();\n                int num = pick.first;\n                int ind = pick.second;\n\n                if(mark[ind] == false) {\n                    mark[ind] = true;\n                    sum -= nums[ind];\n                    cnt--;\n                }\n            }\n\n            ans.push_back(sum);\n        }\n\n        return ans;\n    }\n};\n```\n\n> Please upvote the solution if you like it :)
['Array', 'Sorting', 'Heap (Priority Queue)', 'C++']