Prefix Sum | C++ | Beats 100%
\n\n# Complexity\n- Time complexity: O(nlogn + q)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n + q)\n Add your space complexity here, 
\n\n# Complexity\n- Time complexity: O(nlogn + q)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n + q)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& n, vector<vector<int>>& q) {\n        vector<pair<int,int>>a(n.size());\n        long long sum = 0;\n        for(int i = 0 ; i < n.size() ; i++){\n            a[i] = make_pair(n[i] , i);\n            sum += n[i];\n        }\n        sort(a.begin() , a.end());\n        int j = 0;\n        vector<long long>ans;\n        for(int i = 0 ; i < q.size() ; i++){\n            int cnt = q[i][1];\n            sum -= n[q[i][0]];\n            n[q[i][0]] = 0;\n            while(cnt > 0 && j < a.size()){\n                if(n[a[j].second] > 0){\n                    sum -= n[a[j].second];\n                    n[a[j].second] = 0;\n                    cnt--;\n                }\n                j++;\n            }\n            ans.push_back(sum);\n        }\n        return ans;\n    }\n};\n```
['C++']