Java time O(n log n + k log k) space O(k), detailed comments.
Java\nclass Solution {\n    /*\n\t    Thanks for Huifeng Guan \'s explanation. ref : https://www.youtube.com/watch?v=pquoywwK0_w \n        1. the largest Sum is
```Java\nclass Solution {\n    /*\n\t    Thanks for Huifeng Guan \'s explanation. ref : https://www.youtube.com/watch?v=pquoywwK0_w \n        1. the largest Sum is the sum of all no negative numbers.\n        2. to get the next largest sum we can remove a no negative number (- nogegative) \n        or add a negative number (- abs(negative)).\n        3. the problem turn to (the largest sum) - (the k-th smallest sum of sequence of a nonegative array)\n        4. to get the K smallest sum\n           eg. \n           index:   0, 1, 2, 3\n           arr:    [1, 2, 3, 4]\n           the smallest is 1 then 2, 1+2 could be the second smallest.\n           to get the k smallest sum, please see the following binary tree, \n\t\t   a. the value of the node is the sum of elements in this node.\n           b. we use the 0-th element as the root. \n           c. the left child: remove the parent last number + the next number\n           d. the right child: keep the parent + the next number\n           e. the children are always greater than or equal to (if there are duplicates) its parent. \n\t\t   because the left child use a greater number (the next number) take the place of the \n\t\t   last number in the parent. and the right child add an extra number (the next number)\n                                   1 \n                      2                         1+2\n                3          2+3             1+3          1+2+3\n              4  3+4     2+4  2+3+4     1+4  1+3+4   1+2+4    1+2+3+4\n    */\n    public long kSum(int[] nums, int k) {\n        long maxSum = 0;\n        int n = nums.length;\n        \n        // O(n)\n        for (int i = 0; i < n; i++) {\n            if (nums[i] > 0) maxSum += (long)nums[i];\n            if (nums[i] < 0) nums[i] = -nums[i]; // nums[i] = abs(nums[i]);\n        }\n        \n        // O(n log n)\n        Arrays.sort(nums);\n        // pq long[]{sum, the index of Last Element}, eg 2+3+4 -> {9, 4};\n        PriorityQueue<long[]> pq = new PriorityQueue<>((a, b) -> Long.compare(a[0], b[0]));\n        pq.add(new long[]{nums[0], 0});\n        if (k == 1) return maxSum;\n        \n        // O(k log 2k)\n        while (k-- > 1) {\n            long[] s = pq.poll();\n            long sum = s[0];\n            int lastIndex = (int)s[1];\n            long res = maxSum - sum;\n            \n            if (k == 1) return res;\n            \n            if (lastIndex + 1 < n) {\n                pq.add(new long[]{sum - nums[lastIndex] + nums[lastIndex + 1], lastIndex + 1});\n                pq.add(new long[]{sum + nums[lastIndex + 1], lastIndex + 1});\n            }\n        }\n        \n        return Long.MAX_VALUE; // should never be here.\n    }\n}\n```
[]