3974. Maximum Total Sum of K Selected Elements
You are given an integer array
numsand two integerskandmul.Select exactly
kelements fromnums. Process these elements one by one in any order you choose.For each selected element, independently choose one of the following:
- Add the element’s value to the total sum, or
- Multiply the element by the current value of
muland add the result to the total sum.After processing each selected element,
muldecreases by 1, regardless of which option was chosen. The current value ofmulmay become 0 or negative.Return an integer denoting the maximum possible total sum.
1 | class Solution { |