Java PriorityQueue of Pairs
Complexity\n- Time complexity: O(NlogN)\n\n- Space complexity: O(N)\n\n# Code\n\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] querie
# Complexity\n- Time complexity: O(NlogN)\n\n- Space complexity: O(N)\n\n# Code\n```\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        long sum = 0;\n        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]);\n        for (int i = 0; i < nums.length; i++) {\n            int n = nums[i];\n            sum += n;\n            pq.offer(new int[]{n, i});\n        }\n\n        long[] res = new long[queries.length];\n\n        for (int i = 0; i < queries.length; i++) {\n            int[] q = queries[i];\n            int idx = q[0], k = q[1];\n\n            if (nums[idx] != 0) {\n                sum -= nums[idx];\n                nums[idx] = 0;\n            }\n\n            while (k > 0 && pq.size() > 0) {\n                int[] arr = pq.poll();\n                int val = arr[0], idx1 = arr[1];\n                if (nums[idx1] != 0) {\n                    k--;\n                    sum -= val;\n                    nums[idx1] = 0;\n                }\n            }\n            res[i] = sum;\n        }\n        return res;\n    }\n}\n```
['Java']