Skip to content

Commit 1e338d2

Browse files
Merge pull request #4324 from andreionoie/patch1
Rectify solution description for CSES Max Sum Subarray II
2 parents b7b260b + d740145 commit 1e338d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

solutions/gold/cses-1644.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Therefore, we should construct a prefix sum array to perform these queries.
2020
<Spoiler title="Solution">
2121

2222
Notice that we are trying to maximize $\textrm{pfx}[i] - \textrm{pfx}[j]$. Since
23-
$j$ is guaranteed to be within the window $[i-b,i]$, we can construct a sliding
24-
window of size b, and compute
23+
$j$ is guaranteed to be within the window $[i-b,i-a]$, we can construct a sliding
24+
window of size $b-a+1$, and compute
2525
$\max_{A\le i \le B}(\textrm{pfx}[i]-\textrm{pfx}[j])$.
2626

2727
Implementation using a multiset in C++:
@@ -51,8 +51,8 @@ int main() {
5151
ll ret = -LINF;
5252
multiset<ll> ms;
5353

54-
// we can keep a sliding window of size B, then find the lowest pfx[j] using
55-
// multiset
54+
// we can keep a sliding window of size B - A + 1,
55+
// then find the lowest pfx[j] using multiset
5656
for (int i = A; i <= N; ++i) {
5757
if (i > B)
5858
ms.erase(ms.find(pfx[i - B - 1])); // erase the element if size > B

0 commit comments

Comments
 (0)