Skip to content

Commit 5b75237

Browse files
authored
Update partition-array-for-maximum-sum.cpp
1 parent fd102a1 commit 5b75237

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

C++/partition-array-for-maximum-sum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Solution {
99
for (int i = 0; i < A.size(); ++i) {
1010
int curr_max = 0;
1111
// dp[i % W] = 0; // no need in this problem
12-
for (int k = 1; k <= K && i - k + 1 >= 0; ++k) {
12+
for (int k = 1; k <= min(K, i + 1); ++k) {
1313
curr_max = max(curr_max, A[i - k + 1]);
1414
dp[i % W] = max(dp[i % W], (i >= k ? dp[(i - k) % W] : 0) + curr_max * k);
1515
}

0 commit comments

Comments
 (0)