Solved Simply using heap
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:\nO((M+N) * log N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        \n        \n        PriorityQueue<Pair> pq = new PriorityQueue<>((p1, p2) -> {\n            if (p1.a != p2.a) { \n                return p1.a - p2.a;\n            } else {\n                return p1.b - p2.b; \n            }});\n\n        \n        long ans[] = new long[queries.length];\n        int v = 0;\n        \n        long sum = 0;\n        \n        for(int i= 0 ; i<nums.length ; i++ ){\n            pq.add(new Pair(nums[i],i));\n            sum+=nums[i];\n        }\n        \n        \n        for(int [] p : queries){\n            \n            long lSum = sum;\n            \n            \n            if(nums[p[0]] != -1){\n              lSum -= nums[p[0]];\n            }\n            \n            nums[p[0]] = -1;\n            int count = p[1];\n            \n            while(count>0 &&!pq.isEmpty()){\n                \n                Pair val = pq.poll();\n                \n                if(nums[val.b]==-1) continue;\n                lSum -= val.a;\n                nums[val.b] = -1;\n                count--; \n                \n                \n    \n                \n                if(count == 0) break;\n            }\n            \n            ans[v++] = lSum;\n            \n            sum = lSum;\n            \n        }\n        \n        return ans;\n        \n    }\n}\n\nclass Pair{\n    int a ;\n    int b ; \n    Pair(int a, int b){\n        this.a = a;\n        this.b = b;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']