Maximum absolute sum of a subarray =Max prefix sum — Min prefix sum(prefix sum includes zero).
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Maximum absolute sum of a subarray =Max prefix sum — Min prefix sum(prefix sum includes zero).
Название |
---|
Well this statement isn't exactly true, let me show you why.
take the following array {1,2,-10}
the maximum subarray sum is 1+2=3
but according to your formula its max prefix — min prefix = 3-(-7)=11
which obviously isn't true.
What you're looking for is the maximum value of a prefix sums minus the min prefix sum that ends before it
.
It's the maximum absolute sum of a subarray, so for your array, that would be abs(sum({-10})) = 10, and indeed 3-(-7) = 10.
Oh worry i misread
Notation: $$$n$$$ length of array, $$$a_i$$$ ($$$0 \le i < n$$$) $$$i$$$th element, $$$s_{lr} = \sum_{l\le j<r}a_j$$$ ($$$0 \le l \le r \le n$$$) sum of elements from $$$l$$$ to $$$r$$$, $$$p_i = s_{0i}$$$ prefix sum
Part 1: maximum absolute sum of a subarray $$$\ge$$$ max prefix sum $$$-$$$ min prefix sum
Let $$$p_M$$$ and $$$p_m$$$ be the maximum and minimum prefix sum, respectively. WLOG assume $$$M \le m$$$. Then $$$\max(|s_{lr}|) \ge |s_{Mm}| = |p_m - p_M| = p_M - p_m$$$.
Part 2: maximum absolute sum of a subarray $$$\le$$$ max prefix sum $$$-$$$ min prefix sum
Let $$$L$$$, $$$R$$$ ($$$L\le R$$$) be indices such that $$$\max(|s_{lr}|) = |s_{LR}|$$$. WLOG assume $$$p_L \le p_R$$$. Then, $$$\max(|s_{lr}|) = |s_{LR}| = |p_R - p_L| = p_R - p_L \le \max(p_i) - \min(p_i)$$$.