Java Solution
\nclass Solution {\n    public long kSum(int[] nums, int k) {\n        long sum = 0;\n        Queue<Pair<Long, Integer>> pq = new PriorityQueue<>((a, b) -> Long
```\nclass Solution {\n    public long kSum(int[] nums, int k) {\n        long sum = 0;\n        Queue<Pair<Long, Integer>> pq = new PriorityQueue<>((a, b) -> Long.compare(b.getKey(), a.getKey()));\n        for (int i = 0; i < nums.length; i++) {\n            sum = sum + Math.max(0, nums[i]);\n        }\n        for (int i = 0; i < nums.length; i++) {\n            nums[i] = Math.abs(nums[i]);\n        }\n        Arrays.sort(nums);\n        long result = sum;\n        pq.offer(new Pair<>(sum - nums[0], 0));\n        while (--k > 0) {\n            Pair<Long, Integer> pair = pq.poll();\n            result = pair.getKey();\n            int index = pair.getValue();\n            if (index < nums.length - 1) {\n                pq.offer(new Pair<>(result + nums[index] - nums[index + 1], index + 1));\n                pq.offer(new Pair<>(result - nums[index + 1], index + 1));\n            }\n        }        \n        return result;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']