Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lst = [5, 1, 6, 2, 3, 4, 5, 1]
- # lst = [5, 1, 46, 2, 3, 4, 5]
- if len(lst) == 0:
- raise Exception('Array is empty')
- elif len(lst) == 1:
- print(lst[0])
- else:
- i = 1
- j = 2
- max_sub = lst[0]
- for _ in xrange(len(lst)):
- temp = lst[i:j]
- print('i: {}, j: {}, res: {}'.format(i, j, temp))
- if temp == sorted(temp):
- if sum(temp) > max_sub:
- max_sub = sum(temp)
- j += 1
- else:
- j += 1
- else:
- i = j - 1
- j += 1
- print(max_sub)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement