Description
Given arrays nums and multipliers, perform m operations: multiply nums end with multiplier, add to score, remove from nums. Maximize score.
Examples
Input:
nums = [1,2,3], multipliers = [3,2,1]Output:
14Explanation:
1*3 + 3*2 + 2*1 = 14.
Input:
nums = [1], multipliers = [1]Output:
1Explanation:
Edge case with a single-element array.
Input:
nums = [-5,4,2,-3], multipliers = [2,3]Output:
14Explanation:
Picking from either end of nums: first pick 4 (right end) gives 4*2=8, second pick 2 (new right end) gives 2*3=6. Total: 8+6=14, which beats other combinations.
Constraints
- •
1 ≤ multipliers.length ≤ 1000