Machine Learning coder
In python def max_sum_subarrays(arr):
n = len(arr)
k = n // 3 # size of each window
mod = 10**3 + 7 # modulo value
# initialize windows
window1 = arr[:k]
window2 = arr[k:2*k]
window3 = arr[2*k:3*k]
# initialize sums
sum1 = sum(window1)
sum2 = sum(window2)
sum3 = sum(window3)
# iterate over the rest of the array and update windows and sums
for i in range(k, n-k):
sum1 += arr[i] - window1[i-k]
sum2 += arr[i+k] - window2[i-k]
sum3 += arr[i+2*k] - window3[i-k]
# update windows
window1[i-k] = arr[i]
window2[i-k] = arr[i+k]
window3[i-k] = arr[i+2*k]
# update maximum sums
sum1 = max(sum1, 0)
sum2 = max(sum2, 0)
sum3 = max(sum3, 0)
# return the positive remainder after dividing the sum with modulo value
return (sum1 + sum2 + sum3) % mod
703 ·