Maximum Weighted End-Pick Score
Problem statement
Choose exactly multipliers.length numbers from nums. At each step, remove either the first or last remaining number. Multiply the number chosen at zero-based step i by multipliers[i] and add it to the score.
Return the largest possible total score. The multiplier order is fixed, and every multiplier must be used, even when all possible totals are negative.
Function
maximumWeightedEndScore(nums: int[], multipliers: int[]) → longExamples
Example 1
nums = [1,2,-3,4]multipliers = [1,1,-1,-1]return = 6The source author gives picks 1, 4, -3, 2: their weighted total is 1 + 4 + 3 - 2 = 6.
Example 2
nums = [1,2,3]multipliers = [3,2]return = 13Choose 3 and then 2 from the right: 3 * 3 + 2 * 2 = 13.
Example 3
nums = [-5,-2,-4]multipliers = [1,1]return = -6Choose -4 and then -2; exactly two picks are required.
Constraints
1 <= nums.length <= 100000.1 <= multipliers.length <= min(nums.length, 200).- Every number and multiplier lies between
-10^6and10^6. - Return a signed 64-bit total.