Java Solution with explanation O(N log(N) + k log(k))
from: https://stackoverflow.com/questions/72114300/how-to-generate-k-largest-subset-sums-for-a-given-array-contains-positive-and-n/72117947#72117947\n\nFirst, i
**from:** https://stackoverflow.com/questions/72114300/how-to-generate-k-largest-subset-sums-for-a-given-array-contains-positive-and-n/72117947#72117947\n\nFirst, in a single pass, we find the sum of the positive numbers. This is the maximum sum. We initialize our answer array with [maximum_sum].\n\nNext, we create an array av of the absolute values, sorted from smallest to largest.\n\nNext, we create a priority queue upcoming. It will start with one pair in it. That pair will be (maximum_sum - av[0], 0). The pairs are compared lexicographically with largest sum first.\n\nUntil we have enough elements in answer we will:\n\nget (next_sum, i) from upcoming\nadd next_sum to answer\nif i < N:\n    add (next_sum + av[i] - av[i+1], i+1) to upcoming\n    add (next_sum - av[i+1], i+1) to upcoming\nThis algorithm will take O(N+k) memory and O(N log(N) + k log(k)) work to generate the top k answers. It depends on both N and k but is exponential in neither.\n\n```\nclass Solution {\n    public long kSum(int[] nums, int k) {\n        int n = nums.length;\n        \n        int[] absArray=Arrays.stream(nums).map(i->Math.abs(i)).toArray();\n        Arrays.sort(absArray);\n        \n        long maxSum = Arrays.stream(nums).filter(i -> i > 0).summaryStatistics().getSum();\n        \n\t\tPriorityQueue<long[]> pq=new PriorityQueue<>((a,b)->Long.compare(b[0], a[0]));\n        pq.add(new long[]{maxSum-absArray[0],0});\n        \n        long res = maxSum;\n\t\t\n        while(--k > 0) {\n            long cur[]=pq.poll();\n            long curSum=cur[0];\n            int i=(int)cur[1];\n            res = curSum;\n            \n            if(i + 1 < n) {\n                pq.add(new long[]{curSum+absArray[i]-absArray[i+1],i+1});\n                pq.add(new long[]{curSum-absArray[i+1],i+1});\n            }\n          \n        }\n        \n        return res;\n    }\n}\n```
[]