2
def maxSumAfterPartitioning(self, nums: List[int], k: int) -> int:3
def get_max(start, end):4
return max(nums[start : end + 1]) * (end - start + 1)9
): # base case, so in tabulation we go [N - 1]...[0], as [N] = 013
# you partition at every position up to start + k and repeat the same process for the next partition15
# 1|9|3 => with max in each partition: 1|9|3 = 1316
# 1|9 3 => with max in each partition: 1|9 9 = 1917
# 1 9|3 => with max in each partition: 9 9|3 = 2118
# get max_in_partition(start,end) + give_me_max_for_array(previous_partition_end + 1, N)19
# rec.relation = max(max_sum_in_partition[start, end] + dfs(end + 1)))20
for end in range(start, min(N, start + k)):21
maxi = max(maxi, get_max(start, end) + dfs(end + 1))