write a function to find the K biggest elements in the array, and return the sum in linear time.
Anónimo
pseudocode (assumes k ≤ n and n > 0) sumOfKLargest(k, A[0..n-1]) num ← 1 count ← A[0] lowest ← count for i ← 1 to n-1 do if num ≠ k count ← count + A[i] if A[i] < lowest lowest ← A[i] num ← num + 1 else if lowest < A[i] count ← count - lowest + A[i] lowest ← A[i] return count