Java beat 96%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nUse a TreeMap to help find the smallest k numbers and their indexes\n\n# 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUse a TreeMap to help find the smallest k numbers and their indexes\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        boolean[] marked = new boolean[nums.length];\n        Arrays.fill(marked, false);\n\n        Map<Integer,Queue<Integer>> sortedNums = new TreeMap();\n        long allSum=0;\n        for (int i=0; i<nums.length;i++) {\n            sortedNums.computeIfAbsent(nums[i], k -> new LinkedList()).offer(i);\n            allSum+=nums[i];\n        }\n\n        long[] results = new long[queries.length];\n        for (int j=0; j<queries.length;j++) {\n            long currMarkedSum = 0;\n            int index = queries[j][0];\n            if (!marked[index]) {\n                marked[index] = true;\n                currMarkedSum+=nums[index];\n            }\n\n            int k = queries[j][1];\n            var it = sortedNums.entrySet().iterator(); \n            while (it.hasNext() && k>0) {\n                Map.Entry<Integer, Queue<Integer>> entry = it.next();\n\n                Queue<Integer> indexQueue = entry.getValue();\n                while (!indexQueue.isEmpty() && k>0) {\n                    int c = indexQueue.poll();\n                    if (!marked[c]) {\n                        marked[c] = true;\n                        currMarkedSum+=entry.getKey();\n                        k--;\n                    }\n                }\n\n                if (indexQueue.isEmpty()) {\n                    it.remove();\n                }\n            }\n\n            results[j] = (j==0) ? allSum - currMarkedSum : results[j-1] - currMarkedSum;\n        }\n\n        return results;\n    }\n}\n```
['Java']