You are viewing a single comment's thread. Return to all comments →
Some performance add-ons would be to just add the zero luck values directly to the resultant luck. The new array would only contain the must win.
Sort the array(O(k * log(k)) where k is the number of 1s).
Finally, Iterate the 1s array and where for each n:
if(k <= 0) => result = result - n;
else => result = result + n; k--;
Basically, accumulate all the luck you can until you run out of k, once k is zero, start reducing your luck (you will be spending least luck value for reduction)