HEAP(I am enough for this question)💡💡💡
Complexity\n- Time complexity:\nO(nlogn) \n\n- Space complexity:\nO(n) \n\n# Code\n\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<in
# Complexity\n- Time complexity:\n$$O(nlogn)$$ \n\n- Space complexity:\n$$O(n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& arr, vector<vector<int>>& queries) \n    {\n        long long sum=accumulate(arr.begin(),arr.end(),0LL);\n        priority_queue<pair<long long,long long >,vector<pair<long long,long long>>,greater<pair<long long,long long>>>heap;\n        for(int i=0;i<arr.size();i++)\n          heap.push({arr[i],i});\n        vector<long long>ans;\n        int q=0;\n        while(q<queries.size())\n        {\n            long long index=queries[q][0];\n            long long k=queries[q][1];\n            if(arr[index]>0)\n            {\n                sum-=arr[index];\n                arr[index]*=(-1);\n            }\n            while(!heap.empty() && k-- )\n            {\n                if(arr[heap.top().second]>0)\n                {\n                    sum-=arr[heap.top().second];\n                    arr[heap.top().second]*=(-1);\n                    heap.pop();\n                }\n                else \n                {\n                    k++;\n                    heap.pop();\n                }  \n            }\n            ans.push_back(sum);\n            q++;\n        }\n        return ans;\n    }\n};\n```
['Heap (Priority Queue)', 'C++']