☑️✅Easy Java Solution || Beats 100%✅☑️
Code\n\nclass pair{\n    int num;\n    int ind;\n    pair(int a,int b){\n        num=a;\n        ind=b;\n    }\n}\nclass PairComparator implements Comparator<pa
# Code\n```\nclass pair{\n    int num;\n    int ind;\n    pair(int a,int b){\n        num=a;\n        ind=b;\n    }\n}\nclass PairComparator implements Comparator<pair> {\n    @Override\n    public int compare(pair p1,pair p2) {\n        if (p1.num!=p2.num) {\n            return p1.num - p2.num;\n        } else {\n            return p1.ind - p2.ind;\n        }\n    }\n}\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        int n=nums.length;\n        int m=queries.length;\n        long[]ans=new long[m];\n        long sum=0;\n        PriorityQueue<pair>pq=new PriorityQueue<>(new PairComparator());\n        for(int i=0;i<n;i++){\n            sum+=nums[i];\n            pq.add(new pair(nums[i],i));\n        }\n        HashSet<Integer>st=new HashSet<>();\n        for(int i=0;i<m;i++){\n            int q1=queries[i][0];\n            int k=queries[i][1];\n            if(!st.contains(q1)){\n                sum-=nums[queries[i][0]];\n                st.add(q1);\n            }\n            while(pq.size()>0 && k>0){\n                pair temp=pq.poll();\n                if(!st.contains(temp.ind)){\n                    sum-=temp.num;\n                    st.add(temp.ind);\n                    k--;\n                }\n            }\n            ans[i]=sum;\n        }\n        return ans;\n    }\n}\n```
['Java']