Oct-03-2019, 10:06 PM
(Oct-02-2019, 09:04 PM)Gribouillis Wrote: It seems easy if you defines[j] = sum(arr[i] for i in range(j))
because if the maximum sum of contiguous subarrays is reached for a the range(a, b) of indices, with a <= b, then this sum iss[b] - s[a]
and for all c <= b one hass[b] - s[c] <= s[b] - s[a]
which means thats[a] <= s[c]
, hence s[a] is the minimum value ofs
for all indices smaller than b. Hence the algorithm
start with mv = 0 and sv = 0 and best = 0 for b in range(n): sv += arr[b] mv = min(mv, sv) best = max(best, sv - mv) return best
I didn't understand most of the that, but I'm going to work on it till I do!