Simplest C++ solution || beats 97% || sort || O(N*logN)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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<pair<int, int>>v;\n        vector<int>vis(n,0);\n        vector<long long >ans;\n        long long sum=0;\n        for(int i=0;i<n;i++)\n        {\n            sum+=nums[i];\n            v.push_back({nums[i],i});\n        }\n        int cnt=0;\n        sort(v.begin(), v.end());\n        for(int i=0;i<m;i++)\n        {\n            int idx=queries[i][0];\n            int k=queries[i][1];\n            if(!vis[idx])\n            {\n                vis[idx]=1;\n                sum-=nums[idx];\n            }\n            while(k>0 && cnt<n)\n            {\n                int val=v[cnt].first;\n                int j=v[cnt].second;\n                if(!vis[j])\n                {\n                    sum-=nums[j];\n                    vis[j]=1;\n                    k--;\n                }\n                cnt++;\n            }\n            ans.push_back(sum);\n        }\n        return ans;\n    }\n};\n```
['Sorting', 'C++']