javascript max heap/pq 453ms
\nconst kSum = (a, k) => {\n    let sum = 0, n = a.length, pq = new MaxPriorityQueue({ compare: (x, y) => y[0] - x[0] });\n    for (let i = 0; i < n; i++) {\n  
```\nconst kSum = (a, k) => {\n    let sum = 0, n = a.length, pq = new MaxPriorityQueue({ compare: (x, y) => y[0] - x[0] });\n    for (let i = 0; i < n; i++) {\n        if (a[i] < 0) {\n            a[i] *= -1;\n        } else {\n            sum += a[i];\n        }\n    }\n    if (k == 1) return sum;\n    a.sort((x, y) => x - y);\n    pq.enqueue([sum - a[0], 0]);\n    for (let i = 2; i < k; i++) {\n        let [x, idx] = pq.dequeue();\n        if (idx + 1 < n) {\n            pq.enqueue([x + a[idx] - a[idx + 1], idx + 1]);\n            pq.enqueue([x - a[idx + 1], idx + 1]);\n        }\n    }\n    return pq.front()[0];\n};\n```
['Heap (Priority Queue)', 'JavaScript']