Approach hintTry it first, then revealHide
With prefix sums, let dp[i][j] be the best total using j segments within the first i elements: either skip element i, or end a length-m segment at it and add its sum to dp[i-m][j-1]. O(nk).
With prefix sums, let dp[i][j] be the best total using j segments within the first i elements: either skip element i, or end a length-m segment at it and add its sum to dp[i-m][j-1]. O(nk).