1770. Maximum Score from Performing Multiplication Operations Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [1770] Maximum Score from Performing Multiplication Operations
3 *
4 * You are given two integer arrays nums and multipliers of size n and m respectively, where n >= m. The arrays are 1-indexed.
5 * You begin with a score of 0. You want to perform exactly m operations. On the i^th operation (1-indexed), you will:
6 * 
7 * 	Choose one integer x from either the start or the end of the array nums.
8 * 	Add multipliers[i] * x to your score.
9 * 	Remove x from the array nums.
10 * 
11 * Return the maximum score after performing m operations.
12 *  
13 * Example 1:
14 * 
15 * Input: nums = [1,2,3], multipliers = [3,2,1]
16 * Output: 14
17 * Explanation: An optimal solution is as follows:
18 * - Choose from the end, [1,2,<u>3</u>], adding 3 * 3 = 9 to the score.
19 * - Choose from the end, [1,<u>2</u>], adding 2 * 2 = 4 to the score.
20 * - Choose from the end, [<u>1</u>], adding 1 * 1 = 1 to the score.
21 * The total score is 9 + 4 + 1 = 14.
22 * Example 2:
23 * 
24 * Input: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]
25 * Output: 102
26 * Explanation: An optimal solution is as follows:
27 * - Choose from the start, [<u>-5</u>,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.
28 * - Choose from the start, [<u>-3</u>,-3,-2,7,1], adding -3 * -5 = 15 to the score.
29 * - Choose from the start, [<u>-3</u>,-2,7,1], adding -3 * 3 = -9 to the score.
30 * - Choose from the end, [-2,7,<u>1</u>], adding 1 * 4 = 4 to the score.
31 * - Choose from the end, [-2,<u>7</u>], adding 7 * 6 = 42 to the score. 
32 * The total score is 50 + 15 - 9 + 4 + 42 = 102.
33 * 
34 *  
35 * Constraints:
36 * 
37 * 	n == nums.length
38 * 	m == multipliers.length
39 * 	1 <= m <= 10^3
40 * 	m <= n <= 10^5 
41 * 	-1000 <= nums[i], multipliers[i] <= 1000
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations/
47// discuss: https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn maximum_score(nums: Vec<i32>, multipliers: Vec<i32>) -> i32 {
53        0
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_1770() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.