<garvit244>1043_1.py
def maxSumAfterPartitioning( A, K):
    if not A:
        return 0
    
    N = len(A)
    dp = [0]*(N+1)
    for index_i in range(N):
        maxi = 0
        for index_j in range(index_i, index_i-K, -1):
            if index_j >= 0 and index_j < len(A):
                maxi = max(maxi, A[index_j])
                
                dp[index_i+1] = max(dp[index_i+1], maxi*(index_i-index_j+1)+dp[index_j])
                
    return dp[-1]
def sample_funcname ( var_0 , var_1 ) :
    if not var_0 :
        return 0
    var_4 = len ( var_0 )
    var_6 = [ 0 ] * ( var_4 + 1 )
    for var_8 in range ( var_4 ) :
        var_9 = 0
        for var_10 in range ( var_8 , var_8 - var_1 , - 1 ) :
            if var_10 >= 0 and var_10 < len ( var_0 ) :
                var_9 = max ( var_9 , var_0 [ var_10 ] )
                var_6 [ var_8 + 1 ] = max ( var_6 [ var_8 + 1 ] , var_9 * ( var_8 - var_10 + 1 ) + var_6 [ var_10 ] )
    return var_6 [ - 1 ]
