Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solution(A, K, L):
- # write your code in Python 3.6
- l = len(A)
- if K + L > l:
- return -1
- # i is the start of K
- # j is the start of L
- result = -1
- for i in range(l):
- for j in range(l):
- # K is the first interval
- if not ((i + K > l) or (j + L > l) or (i + K + 1 > j)):
- result = max(sum(A[i:i+K]) + sum(A[j:j+L])
- , result)
- # L is the first interval
- if not ((i + K > l) or (j + L > l) or (j + L + 1 > i)):
- result = max(sum(A[i:i+K]) + sum(A[j:j+L])
- , result)
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement