Advertisement
Guest User

Untitled

a guest
May 27th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def solution(A, K, L):
  2.     # write your code in Python 3.6
  3.     l = len(A)
  4.     if K + L > l:
  5.         return -1
  6.  
  7.     # i is the start of K
  8.     # j is the start of L
  9.     result = -1
  10.     for i in range(l):
  11.         for j in range(l):
  12.             # K is the first interval
  13.             if not ((i + K > l) or (j + L > l) or (i + K + 1 > j)):
  14.                 result = max(sum(A[i:i+K]) + sum(A[j:j+L])
  15.                     , result)
  16.  
  17.             # L is the first interval
  18.             if not ((i + K > l) or (j + L > l) or (j + L + 1 > i)):
  19.                 result = max(sum(A[i:i+K]) + sum(A[j:j+L])
  20.                     , result)
  21.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement