Easy CPP solution using Multiset
Complexity\n- Time complexity: O((N+M)Log(N))\n\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(N+M)\n\n Add your space complexity here, e.
# Complexity\n- Time complexity: O((N+M)Log(N))\n\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N+M)\n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        int n = nums.size();\n        int m = queries.size();\n        vector<long long> ans(m);\n        vector<int> visited(n,0);\n        multiset<pair<int,int>> mt;\n        long long sum = 0;\n        for(int i=0;i<n;i++){\n            mt.insert({nums[i],i});\n            sum += nums[i];\n        }\n        for(int i=0;i<m;i++){\n            int ind = queries[i][0];\n            int k = queries[i][1];\n            if(visited[ind]==0){\n                visited[ind] = 1;\n                sum -= nums[ind];\n                auto it = mt.find({nums[ind],ind});\n                mt.erase(it);\n            }\n            while(!mt.empty() && k--){\n                auto it = mt.begin();\n                if(visited[it->second]==0){\n                    visited[it->second] = 1;\n                    sum -= it->first;\n                    mt.erase(it);\n                }\n            }\n\n            ans[i] = sum;\n        }\n\n        return ans;\n    }\n};\n```
['C++']