Easiest Java Solution || min Heap
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
import java.util.*;

class Solution {
    public long[] unmarkedSumArray(int[] nums, int[][] queries) {
        int n = nums.length;
        long[] result = new long[queries.length];
        boolean[] marked = new boolean[n];
        
        // Min-heap based on value, then index
        PriorityQueue<int[]> minHeap = new PriorityQueue<>((a, b) -> 
            a[0] != b[0] ? Integer.compare(a[0], b[0]) : Integer.compare(a[1], b[1])
        );

        long totalSum = 0;
        for (int i = 0; i < n; i++) {
            minHeap.offer(new int[]{nums[i], i});
            totalSum += nums[i];
        }

        for (int q = 0; q < queries.length; q++) {
            int index = queries[q][0];
            int k = queries[q][1];

            // Step 1: Mark element at index
            if (!marked[index]) {
                marked[index] = true;
                totalSum -= nums[index];
            }

            // Step 2: Mark k smallest unmarked elements
            int count = 0;
            while (count < k && !minHeap.isEmpty()) {
                int[] top = minHeap.peek();
                if (marked[top[1]]) {
                    minHeap.poll(); // discard already marked
                } else {
                    marked[top[1]] = true;
                    totalSum -= nums[top[1]];
                    minHeap.poll();
                    count++;
                }
            }

            result[q] = totalSum;
        }

        return result;
    }
}

```
['Java']