fork download
  1. def main():
  2. vec = [1, 2, 5, -4, 5, 6, -7, 1, -1, -7, 1, -10, 1, -3, 4]
  3. print(vec)
  4. i = 0
  5. n = len(vec)
  6. p = 1
  7. smax = 0
  8. while i < n:
  9. while i < n and vec[i] <= 0:
  10. i += 1
  11. p = i
  12. s = 0
  13. while i < n and vec[i] >= 0:
  14. s += vec[i]
  15. i += 1
  16. if s > smax:
  17. smax = s
  18. pmax = p
  19. lmax = i - p
  20. print("Position: ",pmax)
  21. print("Summa:", smax)
  22. print("Length: ",lmax)
  23. main()
  24.  
Success #stdin #stdout 0.02s 9080KB
stdin
Standard input is empty
stdout
[1, 2, 5, -4, 5, 6, -7, 1, -1, -7, 1, -10, 1, -3, 4]
Position:  4
Summa: 11
Length:  2