Beats 100% | Best Solution | Easy ✅✅
Please Upvote !!\u2705\u2705\n\n# Code\n\nclass Solution {\n    private long sum(int nums[], int[] q,  PriorityQueue<int[]> data , long sum, HashSet<Integer> ma
# Please Upvote !!\u2705\u2705\n\n# Code\n```\nclass Solution {\n    private long sum(int nums[], int[] q,  PriorityQueue<int[]> data , long sum, HashSet<Integer> marked){\n        if(sum == 0)    return 0;\n       \n        int k = q[1];\n        if(nums[q[0]]>0)\n            sum-=nums[q[0]];\n        marked.add(q[0]);\n        \n        nums[q[0]] = -1;\n        \n      \n       \n        int i=0;\n        while(i<k && data.size()>0){\n            i++;\n            int[] temp = data.poll();\n            if(marked.contains(temp[1])) {i--;continue;}\n            sum-=temp[0];\n            nums[temp[1]] = -1;\n            marked.add(temp[1]);\n            \n        }\n        \n      \n        return sum;\n    }\n    \n    \n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        long[] ans = new long[queries.length];\n        PriorityQueue<int[]> data = new PriorityQueue<>((a, b)->{\n            if(a[0]-b[0] == 0)  return a[1]-b[1];\n                \n            return a[0]-b[0];\n });\n        \n        \n        long s = 0;\n        HashSet<Integer> marked = new HashSet<>();\n        \n        for(int i=0;i<nums.length;i++){\n             s+=nums[i];\n            data.add(new int[]{nums[i], i});\n        }\n        \n        for(int i=0;i<queries.length;i++){\n            \n            \n            ans[i] = sum(nums, queries[i], data, s, marked);\n            if(ans[i]<0)    ans[i]=0;\n            s = ans[i];\n            \n        }\n        return ans;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']