My Solution
\n/**\n * Time Complexity: O(n_nums * log(n_nums) + k * log(k)), where `n_nums` is the length of the vector `nums`\n * Space Complexity: O(k)\n */\nclass Soluti
```\n/**\n * Time Complexity: O(n_nums * log(n_nums) + k * log(k)), where `n_nums` is the length of the vector `nums`\n * Space Complexity: O(k)\n */\nclass Solution {\n public:\n  long long kSum(vector<int> &nums, const int k) {\n    long long sum = 0LL;\n    for (int &num : nums) {\n      if (num > 0) {\n        sum += num;\n      }\n      if (num < 0) {\n        num *= -1;\n      }\n    }\n    sort(nums.begin(), nums.end());\n    \n    const int n = static_cast<int>(nums.size());\n    auto compare = [](const pair<long long, int> &lhs, const pair<long long, int> &rhs) -> bool {\n      return !(lhs.first > rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second));\n    };\n    priority_queue<pair<long long, int>, vector<pair<long long, int>>, decltype(compare)> pq(compare);\n    pq.emplace(sum, 0);\n    for (int i = 0; i < k - 1; ++i) {\n      const auto [max_sum, index] = pq.top();\n      pq.pop();\n      if (index >= n) {\n        continue;\n      }\n      pq.emplace(max_sum - nums[index], index + 1);\n      if (index > 0) {\n        pq.emplace(max_sum - nums[index] + nums[index - 1], index + 1);\n      }\n    }\n    return pq.top().first;\n  }\n};\n```
[]