sum to 0.k is less than or equal to numOnes, add k to sum and return sum.numOnes to sum and subtract numOnes from k.k is still greater than 0, subtract the minimum of k and numZeros from k (picking 0s does not change the sum).k is still greater than 0, subtract k from sum (since we are forced to pick -1s).sum.