File tree 2 files changed +6
-5
lines changed
2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -20,16 +20,16 @@ frequency: 2
20
20
### Solution - Max Subarray Sum
21
21
22
22
Consider the prefix sum array $p$. The subarray sum $a_i \dots a_ { j - 1 } $, where
23
- $i\leq j$ is $p[ j] -p[ i] $. Thus, we are looking for the maximum possible value of
24
- $p[ j] -p[ i] $ over $0 \leq i \leq j \leq N$.
23
+ $i < j$ is $p[ j] -p[ i] $. Thus, we are looking for the maximum possible value of
24
+ $p[ j] -p[ i] $ over $0 \leq i < j \leq N$.
25
25
26
26
For a fixed right bound $j$, the maximum subarray sum is
27
27
28
28
$$
29
- p[j]-\min_{i\leq j}{p[i]}
29
+ p[j]-\min_{i < j}{p[i]}
30
30
$$
31
31
32
- Thus, we can keep a running minimum to store $\min\limits_ { i \ leq j }{ p [i ]} $ as we
32
+ Thus, we can keep a running minimum to store $\min\limits_ { i < j }{ p [i ]} $ as we
33
33
iterate through $j$. This yields the maximum subarray sum for each possible
34
34
right bound, and the maximum over all these values is our answer.
35
35
@@ -66,6 +66,7 @@ int main() {
66
66
cout << max_subarray_sum << endl;
67
67
}
68
68
```
69
+
69
70
</CPPSection>
70
71
<JavaSection>
71
72
Original file line number Diff line number Diff line change 238
238
},
239
239
{
240
240
"uniqueId" : " usaco-901" ,
241
- "name" : " Exercise" ,
241
+ "name" : " Exercise Route " ,
242
242
"url" : " http://www.usaco.org/index.php?page=viewproblem2&cpid=901" ,
243
243
"source" : " Platinum" ,
244
244
"difficulty" : " Very Hard" ,
You can’t perform that action at this time.
0 commit comments