3473. Sum of K Subarrays With Length at Least M Medium

@problem@discussion
#Array#Dynamic Programming#Prefix Sum



1/**
2 * [3473] Sum of K Subarrays With Length at Least M
3 *
4 * You are given an integer array nums and two integers, k and m.
5 * Return the maximum sum of k non-overlapping <span data-keyword="subarray">subarrays</span> of nums, where each subarray has a length of at least m.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [1,2,-1,3,3,4], k = 2, m = 2</span>
10 * Output: <span class="example-io">13</span>
11 * Explanation:
12 * The optimal choice is:
13 * 
14 * 	Subarray nums[3..5] with sum 3 + 3 + 4 = 10 (length is 3 >= m).
15 * 	Subarray nums[0..1] with sum 1 + 2 = 3 (length is 2 >= m).
16 * 
17 * The total sum is 10 + 3 = 13.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [-10,3,-1,-2], k = 4, m = 1</span>
22 * Output: <span class="example-io">-10</span>
23 * Explanation:
24 * The optimal choice is choosing each element as a subarray. The output is (-10) + 3 + (-1) + (-2) = -10.
25 * </div>
26 *  
27 * Constraints:
28 * 
29 * 	1 <= nums.length <= 2000
30 * 	-10^4 <= nums[i] <= 10^4
31 * 	1 <= k <= floor(nums.length / m)
32 * 	1 <= m <= 3
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/sum-of-k-subarrays-with-length-at-least-m/
38// discuss: https://leetcode.com/problems/sum-of-k-subarrays-with-length-at-least-m/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn max_sum(nums: Vec<i32>, k: i32, m: i32) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_3473() {
56    }
57}
58

Back
© 2026 bowen.ge All Rights Reserved.