[Java] PriorityQueue  || MaxSum ➖ Kth Smallest Comb Sum
\nclass Solution {\n    public long kSum(int[] nums, int k) {\n        long maxSum = 0L;\n        int n = nums.length;\n        for(int i = 0; i < n; i++){\n   
```\nclass Solution {\n    public long kSum(int[] nums, int k) {\n        long maxSum = 0L;\n        int n = nums.length;\n        for(int i = 0; i < n; i++){\n            if(nums[i] < 0){\n                nums[i] = -nums[i];\n            }else{\n                maxSum += nums[i];\n            }\n        }\n        \n        Arrays.sort(nums);\n\n        // smallest comb to remove\n        PriorityQueue<long[]> pq = new PriorityQueue<long[]>((a, b) -> (a[0] > b[0] ? 1 : a[0] == b[0] ? 0 : -1));\n        pq.offer(new long[]{nums[0], 0});\n        List<Long> removedCombo = new ArrayList<>();\n        \n        if(k == 1) return maxSum;\n        \n        while(!pq.isEmpty() && k > 1){\n            long[] curr = pq.poll();\n            long value = curr[0];\n            long idx = curr[1];\n            removedCombo.add(value);\n            \n            if(idx + 1 < n){\n                pq.offer(new long[]{value + nums[(int)idx + 1], idx + 1});\n                pq.offer(new long[]{value - nums[(int)idx] + nums[(int)idx + 1], idx + 1});\n            }\n            k--;\n        }\n        \n        return maxSum - removedCombo.get(removedCombo.size() - 1);\n        \n    }\n}\n```
['Java']