well commented easy to understand C++ solution with dummy example
\nclass Solution {\npublic:\n    long long kSum(vector<int>& nums, int k) {\n        long long sum = 0;\n        for (auto &n : nums) {\n            if (n >= 0)
```\nclass Solution {\npublic:\n    long long kSum(vector<int>& nums, int k) {\n        long long sum = 0;\n        for (auto &n : nums) {\n            if (n >= 0)\n                sum += n;\n            else\n                n = abs(n);\n        }\n        // get sum of all possitive integers in variable sum\n        // later reverse all negative numbers to possitive as removing them can help \n        \n        // sort helps all the smaller numbers to be tried first so as to reduce total sum\n        // as small as possible\n        sort(nums.begin(),nums.end()); \n        priority_queue<pair<long long, int>> pq;\n        \n        pq.push({sum-nums[0],0});\n        vector<long long> result;\n        result.push_back(sum); // first largest sum we can enter\n        // if no possitive integer then inserting 0 is also fine as \n        // empty sequence is also a subsequence\n       \n        int n = nums.size();\n        while(result.size() < k) {\n            auto [sum,index] = pq.top();\n            result.push_back(sum);\n            pq.pop();\n            // there are 2 possiblitity for current index\n            // extend the sequence with current index\n            // or all the sequence which earlier ended with index \n            // remove than element and insert this index\n            // this cummunlative relation so it will have all cases\n            // for e.g combination of {a,b} with all sequence ending with b will\n            // be {b},{a,b}\n            // so now c will extenend sequence first so it will {b,c},{a,b,c}\n            // by remvoing b and extending sequence from it will be {c}, {a,c}  \n            // thus covering all sequences which ends with c\n            // i.e {b,c},{a,b,c},{c}, {a,c}  \n            if (index+1 < n) {\n                pq.push({sum-nums[index+1],index+1});  // extending the sequence\n                pq.push({sum+nums[index]-nums[index+1], index+1}); // removing the earlier number and adding the current number\n            }\n        }\n        return result[k-1];\n    }\n};\n```
[]