Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. lst = [5, 1, 6, 2, 3, 4, 5, 1]
  2.  
  3. # lst = [5, 1, 46, 2, 3, 4, 5]
  4.  
  5. if len(lst) == 0:
  6. raise Exception('Array is empty')
  7. elif len(lst) == 1:
  8. print(lst[0])
  9. else:
  10. i = 1
  11. j = 2
  12. max_sub = lst[0]
  13. for _ in xrange(len(lst)):
  14. temp = lst[i:j]
  15. print('i: {}, j: {}, res: {}'.format(i, j, temp))
  16. if temp == sorted(temp):
  17. if sum(temp) > max_sub:
  18. max_sub = sum(temp)
  19. j += 1
  20. else:
  21. j += 1
  22. else:
  23. i = j - 1
  24. j += 1
  25.  
  26. print(max_sub)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement