Easy to understand solution using min heap
Code\n\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        // maintaining sum of the entire array\n        long sum = 
# Code\n```\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        // maintaining sum of the entire array\n        long sum = 0;\n        int n = nums.length;\n        // list : [value, idx]\n        PriorityQueue<List<Integer>> pq = new PriorityQueue<>(\n            new Comparator<List<Integer>>(){\n                public int compare(List<Integer> l1, List<Integer> l2){\n                    if(l1.get(0) < l2.get(0)){\n                        return -1;\n                    }\n                    else if(l1.get(0) > l2.get(0)){\n                        return 1;\n                    }\n                    else return l1.get(1) - l2.get(1);\n                }\n            }\n        );\n        long[] ans = new long[queries.length];\n        for(int i = 0; i < n; i++){\n            sum += nums[i];\n            pq.offer(Arrays.asList(nums[i], i));\n        }\n        int idx = 0;\n        int k = 0;\n        List<Integer> curr;\n        // marked array\n        boolean[] visited = new boolean[n];\n        for(int[] query : queries){\n            if(!visited[query[0]]){\n                // marking the index\n                visited[query[0]] = true;\n                // excluding marked values from total sum\n                sum -= nums[query[0]];\n            }\n            k = query[1];\n            while(!pq.isEmpty() && k > 0){\n                curr = pq.poll();\n                if(!visited[curr.get(1)]){\n                    // marking the index\n                    visited[curr.get(1)] = true;\n                    // excluding marked values from total sum\n                    sum -= nums[curr.get(1)];\n                    k--;\n                }\n            }\n            ans[idx++] = sum;\n        }\n        return ans;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']